void disp_time(char *timebuf) { static int8_t ppos = 0; int8_t pos = 0, ytop=1; ht1632_clear(); ht1632_putchar(0,ytop,timebuf[0]); ht1632_putchar(6,ytop,timebuf[1]); ht1632_plot(12,ytop+2,1,0); ht1632_plot(12,ytop+4,1,0); ht1632_putchar(14,ytop,timebuf[2]); ht1632_putchar(20,ytop,timebuf[3]); ppos = pos; }
void demo_life() { uint8_t x,y, neighbors, newval; int i; byte2 xmax = ht1632_xmax(); byte2 ymax = ht1632_ymax(); ht1632_clear(); ht1632_plot(15,9,1,0); // Plant an "acorn"; a simple pattern that ht1632_plot(17,10,1,0); // grows for quite a while.. ht1632_plot(14,11,1,0); ht1632_plot(15,11,1,0); ht1632_plot(18,11,1,0); ht1632_plot(19,11,1,0); ht1632_plot(20,11,1,0); ht1632_plot(seconds%20,10,1,0); // pseudorandom seed ht1632_plot(seconds%17,9,1,0); // pseudorandom seed if(N_PANELS>1) { ht1632_plot(seconds%33,11,1,0); ht1632_plot(seconds/2,12,1,0); ht1632_plot((10+seconds)%36,12,1,0); ht1632_plot(34,11,1,0); ht1632_plot(35,12,1,0); ht1632_plot(36,13,1,0); ht1632_plot(37,13,1,0); ht1632_plot(38,12,1,0); ht1632_plot(39,12,1,0); ht1632_plot(40,11,1,0); ht1632_plot(seconds%37,13,1,0); } _delay_ms(800); // Play life ht1632_snapram(); // 1000 iterations for (i=0; i < 100; i++) { for (x=1; x < xmax; x++) { for (y=1; y < ymax; y++) { neighbors = ht1632_getram(x, y+1) + ht1632_getram(x, y-1) + ht1632_getram(x+1, y) + ht1632_getram(x+1, y+1) + ht1632_getram(x+1, y-1) + ht1632_getram(x-1, y) + ht1632_getram(x-1, y+1) + ht1632_getram(x-1, y-1); switch (neighbors) { case 0: case 1: newval = 0; // death by loneliness break; case 2: // remains the same newval = ht1632_getram(x,y); break; case 3: newval = 1; // grow when you have 3 neighbors break; default: newval = 0; // death by overcrowding break; } ht1632_plot(x,y, newval,0); } } if(last_button1state==0) { ht1632_clear(); return; } ht1632_snapram(); _delay_ms(20); } _delay_ms(1000); }
/* Main Function */ int main(void){ enum states{ setup, drawing, readusart, } currentstate = setup; unsigned char STRING1[]="YAY THIS"; unsigned char STRING2[]="WORKS!!!"; unsigned char STR1CMP[9]; unsigned char STR2CMP[9]; unsigned char x, i, j; unsigned char send[50]; while(1){ switch(currentstate){ case setup: initialize(); clearArray(); PORTB = 0b10000000; PORTC |= 0b10000000; ht1632_initialize(); PORTC |= 0b01000000; InitializeUART(); PORTC |= 0b00100000; sprintf(send, "Initialized...\n"); PORTC |= 0b00010000; SendStringUART(send); _delay_ms(200); PORTC = 0; strcpy(STRING1, "YAY THIS"); strcpy(STRING2, "WORKS!!!"); currentstate = drawing; break; case drawing: for(x=1;x<sizeof(STRING1);x++) { null_buffer(); for(i=0;i<8;i++){ for(j=0;j<8;j++){ set_buffer(STRING1[x-1]); if (~buffer[i][j] & (1<<0)) { ht1632_plot(j+(8*(x-1))-1,i,GREEN); PORTC = ~PORTC; } else { ht1632_plot(j+(8*(x-1))-1,i,BLACK); PORTC = ~PORTC; } } } } for(x=1;x<sizeof(STRING2);x++) { null_buffer(); for(i=0;i<8;i++){ for(j=0;j<8;j++){ set_buffer(STRING2[x-1]); if (~buffer[i][j] & (1<<0)) { ht1632_plot(j+(8*(x-1))-1,i+8,GREEN); PORTC = ~PORTC; } else { ht1632_plot(j+(8*(x-1))-1,i+8,BLACK); PORTC = ~PORTC; } } } } PORTC = 0; currentstate = readusart; break; case readusart: strcpy(STR1CMP, STRING1); strcpy(STR2CMP, STRING2); NewScreen(STRING1, STRING2); if((strcmp(STRING1, "RESETRES") == 0)){ currentstate = setup; }else if((strcmp(STRING1, STR1CMP) != 0) | (strcmp(STRING2, STR2CMP) != 0)){ currentstate = drawing; } break; } } }