// hobbyprojects.com // RGB_Propeller_Clock_timeset_20200107.ino #define RPM 1000 // Change according to your motor RPM. #define red 0x80 #define green 0x40 #define blue 0x20 #define yellow 0xC0 #define cyan 0x60 #define magenta 0xA0 #define white 0xE0 #define black 0x00 int hallSensor_pin = 8; int IR_sensor_pin = 9; int input_state; int IR_input_state; byte color,ch,k,h,m,s,c = 0; unsigned long previousTime = 0; byte hours = 12; byte minutes = 45; byte seconds = 00; PROGMEM const unsigned char number[]{ //0 B11111, B10001, B10001, B10001, B11111, // 1 B00000, B10010, B11111, B10000, B00000, // 2 B11101, B10101, B10101, B10101, B10111, // 3 B10101, B10101, B10101, B10101, B11111, // 4 B00111, B00100, B00100, B00100, B11111, // 5 B10111, B10101, B10101, B10101, B11101, // 6 B11111, B10101, B10101, B10101, B11101, // 7 B00001, B00001, B00001, B11101, B00011, // 8 B11111, B10101, B10101, B10101, B11111, // 9 B10111, B10101, B10101, B10101, B11111, // : B00000, B00000, B01010, B00000, B00000}; void setup() { DDRD = 0xFF; pinMode(hallSensor_pin, INPUT_PULLUP); pinMode(IR_sensor_pin, INPUT_PULLUP); k = 1; color = 0x40; } void loop() { input_state = digitalRead(hallSensor_pin); while (input_state != 0) { getTime(); input_state = digitalRead(hallSensor_pin); } ch = hours/10; displayChar(ch,color); delayMicroseconds(700000/RPM); ch = hours % 10; displayChar(ch,color); IR_input_state = digitalRead(IR_sensor_pin); if(IR_input_state == 0) { if(h == 0) { hours++; if(hours == 24) hours = 0; seconds = 0; h = 1; } } else h = 0; delayMicroseconds(700000/RPM); PORTD = 0xFB; delayMicroseconds(5); PORTD = 0b00011111; ch = 10; // : displayChar(ch,color); delayMicroseconds(700000/RPM); ch = minutes/10; displayChar(ch,color); delayMicroseconds(700000/RPM); ch = minutes % 10; displayChar(ch,color); IR_input_state = digitalRead(IR_sensor_pin); if(IR_input_state == 0) { if(m == 0) { minutes++; if(minutes == 60) minutes = 0; seconds = 0; m = 1; } } else m = 0; delayMicroseconds(700000/RPM); PORTD = 0xFB; delayMicroseconds(5); PORTD = 0b00011111; ch = 10; // : displayChar(ch,color); delayMicroseconds(700000/RPM); ch = seconds/10; displayChar(ch,color); delayMicroseconds(700000/RPM); ch = seconds % 10; displayChar(ch,color); IR_input_state = digitalRead(IR_sensor_pin); if(IR_input_state == 0) { if(s == 0) { seconds++; if(seconds == 60) seconds = 0; s = 1; } } else s = 0; delayMicroseconds(700000/RPM); PORTD = 0xFB; delayMicroseconds(5); PORTD = 0b00011111; delayMicroseconds(10000000/RPM); PORTD = 0xFB; delayMicroseconds(300000/RPM); PORTD = 0b00011111; IR_input_state = digitalRead(IR_sensor_pin); if(IR_input_state == 0) { if(c == 0) { color = white; c = 1; } } else c = 0; PORTD = 0xFB; delayMicroseconds(1000000/RPM); PORTD = 0b00011111; PORTD = 0xBB; delayMicroseconds(300000/RPM); PORTD = 0b00011111; IR_input_state = digitalRead(IR_sensor_pin); if(IR_input_state == 0) { if(c == 0) { color = magenta; c = 1; } } else c = 0; PORTD = 0xBB; delayMicroseconds(1000000/RPM); PORTD = 0b00011111; PORTD = 0x7B; delayMicroseconds(300000/RPM); PORTD = 0b00011111; IR_input_state = digitalRead(IR_sensor_pin); if(IR_input_state == 0) { if(c == 0) { color = cyan; c = 1; } } else c = 0; PORTD = 0x7B; delayMicroseconds(1000000/RPM); PORTD = 0b00011111; PORTD = 0xDB; delayMicroseconds(300000/RPM); PORTD = 0b00011111; IR_input_state = digitalRead(IR_sensor_pin); if(IR_input_state == 0) { if(c == 0) { color = yellow; c = 1; } } else c = 0; PORTD = 0xDB; delayMicroseconds(1000000/RPM); PORTD = 0b00011111; PORTD = 0x3B; delayMicroseconds(300000/RPM); PORTD = 0b00011111; IR_input_state = digitalRead(IR_sensor_pin); if(IR_input_state == 0) { if(c == 0) { color = blue; c = 1; } } else c = 0; PORTD = 0x3B; delayMicroseconds(1000000/RPM); PORTD = 0b00011111; PORTD = 0x5B; delayMicroseconds(300000/RPM); PORTD = 0b00011111; IR_input_state = digitalRead(IR_sensor_pin); if(IR_input_state == 0) { if(c == 0) { color = green; c = 1; } } else c = 0; PORTD = 0x5B; delayMicroseconds(1000000/RPM); PORTD = 0b00011111; PORTD = 0x9B; delayMicroseconds(300000/RPM); PORTD = 0b00011111; IR_input_state = digitalRead(IR_sensor_pin); if(IR_input_state == 0) { if(c == 0) { color = red; c = 1; } } else c = 0; PORTD = 0x9B; delayMicroseconds(1000000/RPM); PORTD = 0b00011111; ; input_state = digitalRead(hallSensor_pin); while (input_state == 0) { getTime(); input_state = digitalRead(hallSensor_pin); } } void displayChar(char c, char color) { int a; byte x; if((c >= 0) && (c <= 15)) { a = c*5; for(int i = 0; i < 5; i++) { x = pgm_read_byte(&(number+a)[i]); x = ~x; x &= 0x1F; x |= color; PORTD = x; delayMicroseconds(100000/RPM); // for LED pixel width PORTD = 0b00011111; delayMicroseconds(500000/RPM); // for gap between the columns } } } void getTime() { if (millis() >= (previousTime)) { previousTime = previousTime + 1000; seconds = seconds +1; if (seconds == 60) { seconds = 0; minutes = minutes +1; } if (minutes == 60) { minutes = 0; hours = hours +1; } if (hours == 24) { hours = 0; } } }