I’m terrible with time conversion. Even when it’s simple conversion, for example 12 hour between between Shanghai and New York, I still get confused with the date. My goal is to create a device that will facilitate appointments making across time zones.
On p5.js, I created a tool that allows the user to select a target time zone, and see the time and date there by toggling through user’s local time. I am going to create a physical way to interact with the slider, and the buttons with Arduino Nano 33 IoT.
The device has two parts: p5.js and Arduino. The user will be able to change the source time zone date, hour, and minute, and to choose the target time zone with four rotary encoders / potentiometers. p5.js will then do the conversion and light up one of the two LEDs to indicate AM/PM in the target time zone.
System Diagram
Breadboard
BOM
Component | Quantity ¥ | Unit Price |
Arduino Nano 33 IoT | 1 | 220 |
Jumper Wires | 1 set | 3.69 |
Breadboard | 1 | 6 |
Potentiometer | 4 | 3.21 |
LED | 2 | 2 |
Resistor | 2 | 2 |
Demo
Special thanks to Yuchen who helped me debug the code!
To-do list
-
- Find out a way to stabilize the readings so the numbers don’t flash.
so far I have tested the following code to be working on one reading:
/*
SmoothingReads repeatedly from an analog input, calculating a running average and
printing it to the computer. Keeps ten readings in an array and continually
averages them.The circuit:
– analog sensor (potentiometer will do) attached to analog input 0created 22 Apr 2007
by David A. Mellis <dam@mellis.org>
modified 9 Apr 2012
by Tom IgoeThis example code is in the public domain.
https://www.arduino.cc/en/Tutorial/BuiltInExamples/Smoothing
*/// Define the number of samples to keep track of. The higher the number, the
// more the readings will be smoothed, but the slower the output will respond to
// the input. Using a constant rather than a normal variable lets us use this
// value to determine the size of the readings array.
const int numReadings = 200;int readings[numReadings]; // the readings from the analog input
int readIndex = 0; // the index of the current reading
int total = 0; // the running total
int average = 0; // the averageint inputPin = A0;
void setup() {
// initialize serial communication with computer:
Serial.begin(9600);
// initialize all the readings to 0:
for (int thisReading = 0; thisReading < numReadings; thisReading++) {
readings[thisReading] = 0;
}
}void loop() {
// subtract the last reading:
total = total – readings[readIndex];
// read from the sensor:
readings[readIndex] = analogRead(inputPin);
// add the reading to the total:
total = total + readings[readIndex];
// advance to the next position in the array:
readIndex = readIndex + 1;// if we’re at the end of the array…
if (readIndex >= numReadings) {
// …wrap around to the beginning:
readIndex = 0;
}// calculate the average:
average = total / numReadings;
// send it to the computer as ASCII digits
Serial.println(average);
delay(1); // delay in between reads for stability
}I still need to figure out how to incorporate it into the for-loop so it works on all four values.
- Find out a way to stabilize the readings so the numbers don’t flash.
- Add the feature to turn on LED with the output from p5.js to Arduino as a feedback.
- Add sound effects when turning the potentiometer as a feedback.
Leave a Reply