void displayBlink(uint8_t reps){ int rep = 0; for(rep = 0; rep < reps; rep++){ firstDisplay(0b1111); secondDisplay(0b1111); _delay_ms(500); firstDisplay(8); secondDisplay(8); _delay_ms(500); } }
void display_Selection(uint8_t selection){ if(selection < 10){ firstDisplay(0); secondDisplay(selection); } else{ uint8_t first_digit = selection / 10; uint8_t second_digit = selection % 10; firstDisplay(first_digit); secondDisplay(second_digit); } }
//keyboard callback void keyboard(unsigned char key, int x,int y){ switch(key){ case 'p': //postavka primarnog prikaza baseDisplay(); break; case 'd': //prva dva nisu konektovana secondDisplay(); break; case 'e': //brisanje prikaza glClear(GL_COLOR_BUFFER_BIT); break; case 27: //ESC taster exit(0); } glFlush(); }
int main (void){ //Start UART init_UART(); stdout = &uart_tx; stdin = &uart_rx; //Start ADC init_ADC(); //Set pins for display as output //Digit 1 DDRD |= (1 << PD5); //A DDRD |= (1 << PD6); //B DDRD |= (1 << PD7); //C DDRB |= (1 << PB0); //D //Digit 2 DDRC |= (1 << PC1); //A DDRC |= (1 << PC2); //B DDRC |= (1 << PC3); //C DDRC |= (1 << PC4); //D //Lights Pin Output DDRC |= (1 << PC5); //Start/Stop Button DDRB &= ~(1 << PB1); //Start button input DDRB &= ~(1 << PB2); //Stop button input //Buzzer Pin DDRD |= (1 << PD2); //Output int first_digit = 9; int second_digit = 10; static long reading; static bool btnStart; //Blink display to let me know everything is good! displayBlink(5); while(1) { printf("Raw Reading: %d\t",read_ADC(0,&reading)); long mapped_reading = mapRange(0,1023,0,99,reading); printf("Mapped Reading: %d\n",mapped_reading); display_Selection(mapped_reading); if(PINB & (1 << PB1) && mapped_reading > 0 ){ //If the Start button gets pressed then displayBlink(2); int count = 0; _delay_ms(1000); PORTC |= (1 << PC5); for(count = mapped_reading;count >= 0;count--){ //Count Backwards from that number //Check for stop button quit if set if(PINB & (1 << PB2)) break; uint8_t fdigitm = count / 10; uint8_t sdigitm = count % 10; firstDisplay(fdigitm); secondDisplay(sdigitm); printf("UV Lights on for: %d more secs...\n",count); _delay_ms(1000); } PORTC &= ~(1 << PC5); //displayBlink(5); alarmSound(2); displayBlink(2); } } }