// hobbyprojects.com // RGB_Color_Changing_Propeller_Clock_12_12_2019.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 sensor_pin = 8; int input_state; byte color,color1,color2,color3,ch,k; 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(sensor_pin, INPUT_PULLUP); color = red; k = 1; } void loop() { input_state = digitalRead(sensor_pin); while (input_state != 0) { getTime(); input_state = digitalRead(sensor_pin); } ch = hours/10; color = color1; displayChar(ch,color); ch = hours % 10; displayChar(ch,color); ch = 10; // : color = white; displayChar(ch,color); ch = minutes/10; color = color2; displayChar(ch,color); ch = minutes % 10; displayChar(ch,color); ch = 10; // : color = white; displayChar(ch,color); ch = seconds/10; color = color3; displayChar(ch,color); ch = seconds % 10; displayChar(ch,color); input_state = digitalRead(sensor_pin); while (input_state == 0) { getTime(); input_state = digitalRead(sensor_pin); } } void displayChar(char c, char color) { int a; byte x; if((c >= 0) && (c <= 10)) { 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, // blank delayMicroseconds(500000/RPM); // for gap between the columns } delayMicroseconds(700000/RPM); // for gap between the chars } } 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; } k++; if(k > 6) k = 1; if( k == 1) { color1 = red; color2 = green; color3 = blue; } else if( k == 2) { color1 = green; color2 = blue; color3 = cyan; } else if( k == 3) { color1 = blue; color2 = cyan; color3 = magenta; } else if( k == 4) { color1 = magenta; color2 = yellow; color3 = white; } else if( k == 5) { color1 = yellow; color2 = white; color3 = red; } else if( k == 6) { color1 = white; color2 = red; color3 = green; } } }