// hobbyprojects // 22-07-2019 ArduinoNanoPropellerClock_220719.ino unsigned int x,j,n,d,nm,dl,str_l; unsigned long previousTime,rpm,tc,to = 0; long v; byte hours = 12; byte minutes = 15; byte seconds = 00; int i,m,f,k1,k = 0; byte a,c,c1,c2; char s,ch,z; String s1,s2; String str, str_t, str_b; const PROGMEM unsigned char data[]={0x3f,0x23,0x23,0x3f,0x01,0x13,0x3f,0x03,0x2f,0x2b,0x2b,0x3b,0x2b,0x2b,0x2b,0x3f,0x39,0x09,0x09,0x3f,0x3b,0x2b,0x2b,0x2f,0x3f,0x2b,0x2b,0x2f,0x21,0x27,0x29,0x31,0x3f,0x2b,0x2b,0x3f,0x3b,0x2b,0x2b,0x3f,0x00,0x00,0x15,0x00,0x01,0x01,0x3f,0x29,0x2d,0x13,0x01,0x3f,0x29,0x29,0x11,0x01,0x3f,0x11,0x09,0x11,0x3f,0x39,0x05,0x03,0x05,0x39,0x1F,0x11,0x11,0x00,0x1F,0x01,0x01,0x01,0x1f,0x11,0x11,0x1F,0x1F,0x11,0x11,0x00,0x1F,0x04,0x0A,0x11}; const PROGMEM unsigned char data2[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x79,0x00,0x00,0x00,0x70,0x00,0x70,0x00,0x14,0x7f,0x14,0x7f,0x14, 0x12,0x2a,0x7f,0x2a,0x24,0x62,0x64,0x08,0x13,0x23,0x36,0x49,0x55,0x22,0x05,0x00,0x50,0x60,0x00,0x00, 0x00,0x1c,0x22,0x41,0x00,0x00,0x41,0x22,0x1c,0x00,0x14,0x08,0x3e,0x08,0x14,0x08,0x08,0x3e,0x08,0x08, 0x00,0x05,0x06,0x00,0x00,0x08,0x08,0x08,0x08,0x08,0x00,0x03,0x03,0x00,0x00,0x02,0x04,0x08,0x10,0x20, 0x3e,0x45,0x49,0x51,0x3e,0x00,0x21,0x7f,0x01,0x00,0x21,0x43,0x45,0x49,0x31,0x42,0x41,0x51,0x69,0x46, 0x0c,0x14,0x24,0x7f,0x04,0x72,0x51,0x51,0x51,0x5e,0x1e,0x29,0x49,0x49,0x06,0x40,0x47,0x48,0x50,0x60, 0x36,0x49,0x49,0x49,0x36,0x30,0x49,0x49,0x4a,0x3c,0x00,0x36,0x36,0x00,0x00,0x00,0x35,0x36,0x00,0x00, 0x08,0x14,0x22,0x41,0x00,0x14,0x14,0x14,0x14,0x14,0x00,0x41,0x22,0x14,0x08,0x20,0x40,0x45,0x48,0x30, 0x26,0x49,0x4f,0x41,0x3e,0x3f,0x44,0x44,0x44,0x3f,0x7f,0x49,0x49,0x49,0x36,0x3e,0x41,0x41,0x41,0x22, 0x7f,0x41,0x41,0x22,0x1c,0x7f,0x49,0x49,0x49,0x41,0x7f,0x48,0x48,0x48,0x40,0x3e,0x41,0x49,0x49,0x2f, 0x7f,0x08,0x08,0x08,0x7f,0x00,0x41,0x7f,0x41,0x00,0x02,0x01,0x41,0x7e,0x40,0x7f,0x08,0x14,0x22,0x41, 0x7f,0x01,0x01,0x01,0x01,0x7f,0x20,0x18,0x20,0x7f,0x7f,0x10,0x08,0x04,0x7f,0x3e,0x41,0x41,0x41,0x3e, 0x7f,0x48,0x48,0x48,0x30,0x3e,0x41,0x45,0x42,0x3d,0x7f,0x48,0x4c,0x4a,0x31,0x31,0x49,0x49,0x49,0x46, 0x40,0x40,0x7f,0x40,0x40,0x7e,0x01,0x01,0x01,0x7e,0x7c,0x02,0x01,0x02,0x7c,0x7e,0x01,0x0e,0x01,0x7e, 0x63,0x14,0x08,0x14,0x63,0x70,0x08,0x07,0x08,0x70,0x43,0x45,0x49,0x51,0x61,0x00,0x7f,0x41,0x41,0x00, 0x54,0x34,0x1f,0x34,0x54,0x00,0x41,0x41,0x7f,0x00,0x10,0x20,0x40,0x20,0x10,0x01,0x01,0x01,0x01,0x01, 0x00,0x40,0x20,0x10,0x00,0x02,0x15,0x15,0x15,0x0f,0x7f,0x09,0x11,0x11,0x0e,0x0e,0x11,0x11,0x11,0x02, 0x0e,0x11,0x11,0x09,0x7f,0x0e,0x15,0x15,0x15,0x0c,0x08,0x3f,0x48,0x40,0x20,0x18,0x25,0x25,0x25,0x3e, 0x7f,0x08,0x10,0x10,0x0f,0x00,0x11,0x5f,0x01,0x00,0x02,0x01,0x11,0x5e,0x00,0x7f,0x04,0x0a,0x11,0x00, 0x00,0x41,0x7f,0x01,0x00,0x1f,0x10,0x0c,0x10,0x0f,0x1f,0x08,0x10,0x10,0x0f,0x0e,0x11,0x11,0x11,0x0e, 0x1f,0x14,0x14,0x14,0x08,0x08,0x14,0x14,0x0c,0x1f,0x1f,0x08,0x10,0x10,0x08,0x09,0x15,0x15,0x15,0x02, 0x10,0x7e,0x11,0x01,0x02,0x1e,0x01,0x01,0x02,0x1f,0x1c,0x02,0x01,0x02,0x1c,0x1e,0x01,0x06,0x01,0x1e, 0x11,0x0a,0x04,0x0a,0x11,0x18,0x05,0x05,0x05,0x1e,0x11,0x13,0x15,0x19,0x11,0x00,0x08,0x36,0x41,0x00, 0x00,0x00,0x7f,0x00,0x00,0x00,0x41,0x36,0x08,0x00,0x08,0x08,0x2a,0x1c,0x08,0x08,0x1c,0x2a,0x08,0x08}; void setup() { Serial.setTimeout(3); Serial.begin(9600); DDRD = 0xF8; DDRB = 0xFF; DDRC = 0xFE; PORTC = 0x01; PORTD = 0x07; PORTB = 0x00; attachInterrupt(0, usdl, RISING); if(hours > 11) hours = hours - 12; m = 0; } void loop() { if(Serial.available()) { s1 = Serial.readString(); k1 = s1.indexOf("Connecting to"); if( k1 != -1) { m = 2; str_l = s1.length(); str_t = s1.substring(k1, 13); str_b = s1.substring(14, str_l); } k1 = s1.indexOf("IP address: "); if( k1 != -1) { m = 3; str_l = s1.length(); str_t = s1.substring(k1, 9); str_b = s1.substring(12, str_l); } k1 = s1.indexOf("mode="); if( k1 != -1) { if(s1.charAt(5)=='0') m = 0; if(s1.charAt(5)=='1') m = 1; } k1 = s1.indexOf("time="); if( k1 != -1) { c1 = s1.charAt(5)-'0'; c2 = s1.charAt(6)-'0'; hours = c1*10+c2; c1 = s1.charAt(7)-'0'; c2 = s1.charAt(8)-'0'; minutes = c1*10+c2; c1 = s1.charAt(9)-'0'; c2 = s1.charAt(10)-'0'; seconds = c1*10+c2; if(hours > 11) hours = hours - 12; } if((m == 2) || (m == 3)) { str = s1; } s1 = ""; } if(m == 2) { while(bit_is_clear(PIND, 2)) { } str = " "; dstr(); str = str_t; dstr(); str_l = str_b.length(); if(str_l > 15) str_l = 15; if(str_l > 15) str = " "; if(str_l == 15) str = " "; if(str_l == 14) str = " "; if(str_l == 13) str = " "; if(str_l == 12) str = " "; if(str_l == 11) str = " "; if(str_l == 10) str = " "; if(str_l == 9) str = " "; if(str_l == 8) str = " "; if(str_l == 7) str = " "; if(str_l == 6) str = " "; if(str_l == 5) str = " "; if(str_l == 4) str = " "; if(str_l == 3) str = " "; if(str_l < 3) str = " "; dstr(); str = str_b; dstr_b(); } if(m == 3) { while(bit_is_clear(PIND, 2)) { } str = " "; dstr(); str = str_t; dstr(); str_l = str_b.length(); if(str_l > 15) str_l = 15; if(str_l > 15) str = " "; if(str_l == 15) str = " "; if(str_l == 14) str = " "; if(str_l == 13) str = " "; if(str_l == 12) str = " "; if(str_l == 11) str = " "; if(str_l < 11) str = " "; dstr(); str = str_b; dstr_b(); } if(m == 0) { while(bit_is_clear(PIND, 2)) { } k=45; n=0; while(n < 60) { PORTC |= (1<<5); if ((k==0) || (k==5) || (k==10) || (k==15) || (k==20) || (k==25) || (k==30) || (k==35) || (k==40) || (k==45) || (k==50) || (k==55)) { PORTC |= (1<<4); PORTC |= (1<<3); } if ((k==0) || (k==15) || (k==30) || (k==45)) { PORTC |= (1<<2); PORTC |= (1<<1); } if(k == hours*5 - 1) PORTD |= (1<<7); if((k == hours*5) || (( k == 0 ) && (hours == 0))) { PORTB |= (1<<5); PORTD |= (1<<3); PORTD |= (1<<4); PORTD |= (1<<5); PORTD |= (1<<6); PORTD |= (1<<7); PORTB |= (1<<0); } if(k == hours*5 + 1) PORTD |= (1<<7); if((k == 59) && (hours*5 == 0)) PORTD |= (1<<7); if(k == minutes-1) PORTB |= (1<<1); if(k == minutes) { PORTB |= (1<<5); PORTD |= (1<<3); PORTD |= (1<<4); PORTD |= (1<<5); PORTD |= (1<<6); PORTD |= (1<<7); PORTB |= (1<<0); PORTB |= (1<<1); PORTB |= (1<<2); } if(k == minutes+1) PORTB |= (1<<1); if((k == 0) && (minutes == 59)) PORTB |= (1<<1); if((k == 59) && (minutes == 0)) PORTB |= (1<<1); if(k == seconds-1) PORTB |= (1<<3); if(k == seconds) { PORTB |= (1<<5); PORTD |= (1<<3); PORTD |= (1<<4); PORTD |= (1<<5); PORTD |= (1<<6); PORTD |= (1<<7); PORTB |= (1<<0); PORTB |= (1<<1); PORTB |= (1<<2); PORTB |= (1<<3); PORTB |= (1<<4); } if(k == seconds+1) PORTB |= (1<<3); if((k == 0) && (seconds == 59)) PORTB |= (1<<3); if((k == 59) && (seconds == 0)) PORTB |= (1<<3); delayMicroseconds(dl); PORTD = 0x07; PORTB = 0x00; PORTC = 0x01; PORTB |= (1<<5); delayMicroseconds(dl/50); PORTB &= ~(1<<5); delayMicroseconds(dl*4); n++; k++; if(k == 60) k=0; } } if(m == 1) { while(bit_is_clear(PIND, 2)) { } ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); delay(2); ADCSRA |= _BV(ADSC); while (bit_is_set(ADCSRA,ADSC)); v = ADCL; v |= ADCH<<8; v = 1125300L / v; nm = v/1000; nm = nm%10; nD(); delayMicroseconds(dl*4); PORTC = 0x03; delayMicroseconds(dl); PORTC = 0x01; delayMicroseconds(dl*6); nm = v/100; nm = nm%10; nD(); delayMicroseconds(dl*2); nm = v/10; nm = nm%10; nD(); delayMicroseconds(dl*2); i = 0; while(i < 5) { PORTC = (pgm_read_byte(&(data+61)[i])); delayMicroseconds(dl); PORTC = 0x01; delayMicroseconds(dl*2); i++; } i = 0; while(i < 10) { delayMicroseconds(dl); i++; } rpm = (100000000/tc)*60; nm = rpm/100000; nm = nm%10; if(nm !=0) nD(); delayMicroseconds(dl*2); nm = rpm/10000; nm = nm%10; nD(); delayMicroseconds(dl*2); nm = rpm/1000; nm = nm%10; nD(); delayMicroseconds(dl*2); nm = rpm/100; nm = nm%10; nD(); delayMicroseconds(dl*2); i = 0; while(i < 17) { PORTC = (pgm_read_byte(&(data+44)[i])); delayMicroseconds(dl); PORTC = 0x01; delayMicroseconds(dl*2); i++; } while(i < 40) { delayMicroseconds(dl); i++; } nm = seconds; nm = nm%10; nmDB(); delayMicroseconds(dl*2); nm = seconds/10; nm = nm%10; x=4; nmDB2(); delayMicroseconds(dl*2); nm = 10; x=3; nmDB2(); delayMicroseconds(dl*2); nm = minutes; nm = nm%10; x=2; nmDB2(); delayMicroseconds(dl*2); nm = minutes/10; nm = nm%10; x=1; nmDB2(); delayMicroseconds(dl*2); nm = 10; x=0; nmDB2(); delayMicroseconds(dl*2); nm = hours; if(nm == 0) nm = 12; nm = nm%10; nmDB(); delayMicroseconds(dl*2); nm = hours; if(nm == 0) nm = 12; nm=nm/10; nm = nm%10; nmDB(); } while(bit_is_set(PIND, 2)) { } } void nD() { j=nm*4; i = 0; while(i < 4) { PORTC = (pgm_read_byte(&(data+j)[i])); delayMicroseconds(dl); PORTC = 0x01; delayMicroseconds(dl*2); i++; } } void nmDB2() { j=nm*4; x = x*4; i = 3; while(i >= 0) { c = (pgm_read_byte(&(data+j)[i])); s=0; for(a = 0; a < 8; a++){ s <<= 1; s |= c & 1; c >>= 1; } s >>= 1; PORTC = s; PORTB &= ~(1<<5); delayMicroseconds(dl); PORTC = 0x01; PORTB = 0x00; PORTD = 0x04; delayMicroseconds(dl*2); i--; } } void nmDB() { j=nm*4; i = 3; while(i >= 0) { c = (pgm_read_byte(&(data+j)[i])); s=0; for(a = 0; a < 8; a++){ s <<= 1; s |= c & 1; c >>= 1; } s >>= 1; PORTC = s; delayMicroseconds(dl); PORTC = 0x01; delayMicroseconds(dl*2); i--; } } void usdl() { f = 0; n = 0; tc = micros()-to; to = micros(); f = 1; if(m == 0) dl = tc/315; // for analog clock else if(m == 1) dl = tc/350; // for digital clock else if(m == 2) dl = tc/700; else if(m == 3) dl = tc/700; 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 == 12) { hours = 0; } } } void dstr() { str_l = str.length(); k = 0; while(k < str_l) { ch = str[k]; dch(); delayMicroseconds(dl*5); k++; } } void dch() { if(ch == 0x0D) return; if(ch == 0x0A) return; if(ch == 0x00) return; j = ch; j = j - 32; j = j*5; i = 0; while(i < 5) { c = (pgm_read_byte(&(data2+j)[i])); disp_ch(); delayMicroseconds(dl); PORTD = 0x07; PORTB = 0x00; PORTC = 0x00; delayMicroseconds(dl*2); i++; } } void disp_ch() { if(c & 1) PORTB |= (1<<3); else PORTB &= ~(1<<3); if(c & 2) PORTB |= (1<<4); else PORTB &= ~(1<<4); if(c & 4) PORTC |= (1<<1); else PORTC &= ~(1<<1); if(c & 8) PORTC |= (1<<2); else PORTC &= ~(1<<2); if(c & 16) PORTC |= (1<<3); else PORTC &= ~(1<<3); if(c & 32) PORTC |= (1<<4); else PORTC &= ~(1<<4); if(c & 64) PORTC |= (1<<5); else PORTC &= ~(1<<5); } void dstr_b() { str_l = str_b.length(); if(str_l > 15) str_l = 15; k = str_l; ch = 0; while(k >= 0) { ch = str[k]; dch_b(); delayMicroseconds(dl*5); k--; } } void dch_b() { j = ch; if(j < 32) return; j = j - 32; j = j*5; i = 4; while(i >= 0) { c = (pgm_read_byte(&(data2+j)[i])); s=0; for(a = 0; a < 8; a++) { s <<= 1; s |= c & 1; c >>= 1; } s >>= 1; c = s; disp_ch(); delayMicroseconds(dl); PORTD = 0x07; PORTB = 0x00; PORTC = 0x00; delayMicroseconds(dl*2); i--; } }