int main() { init_timer_0(); init_pin_interrupt(PCINT0); init_adc(); util_init(); // Outputs DDRB |= (1 << PB1); DDRB |= (1 << PB3); DDRB |= (1 << PB4); PORTB &= ~(1 << PB3); // Set LED low PORTB &= ~(1 << PB1); // Set Servo pin low // Inputs DDRB &= ~(1 << PB0); /* Set PB0 as input */ PORTB |= (1 << PB0); /* Activate PULL UP resistor */ // Toggle LED PORTB ^= (1 << PB3); _delay_ms(1000); PORTB ^= (1 << PB3); // Enable global interrupts sei(); while(1) { reading = read_analog(); reading_map = map(reading, 0, 255, 410, 1580, 1) / 1000.0 / 0.01; } }
int main(void) { // open the Character LCD port char_lcd_dev = alt_up_character_lcd_open_dev ("/dev/LCD"); /* Initialize the character display */ alt_up_character_lcd_init(char_lcd_dev); // Initially writes the start time of timer to lcd write_time_to_buffer(top_row, seconds, minutes, hours, am_pm_mode); hex_write_date(month, day, year); // Initialize the switches int * sw_ptr = (int *) SW_BASE; int sw_values; int oldvalue = 0x00000000; // Masks for individual switches int MASK_17 = 0x00020000; int MASK_16 = 0x00010000; int MASK_1 = 0x00000002; int MASK_0 = 0x00000001; int is_fast = 0; //use to tell other function if sped up, 0 = slow, 1 = fast int clk_modify = 0; //if 0, clock isn't being changed, if 1 clock is being changed int alarm_modify = 0; //if 0 alarm isn't being changed, if 1, alarm is being changed // Initialize the Timers init_timer_0(&tenths); // Tracker to see when the time changes int old_tenths = 0; // Initialize the KEY port init_button_pio(); // continually while(1) { // check the state of the context integer updated by various ISR functions // Act accordingly, which means // Update the switch_values sw_values = *(sw_ptr); //check if sw17 is up and if it is, then speed up the timer if((sw_values & MASK_17) == 0x00020000 && oldvalue == 0x00000000){ speed_up(); oldvalue = sw_values & MASK_17; is_fast = 1; } //check if sw17 is down and if it is then slow down the timer else if ((sw_values & MASK_17) == 0x00000000 && oldvalue == 0x00020000) { slow_down(); oldvalue = sw_values & MASK_17; is_fast = 0; } // Allow user to change the time if SW0 is up if((sw_values & MASK_0) == 0x00000001){ clk_modify = 1; } else{ clk_modify = 0; } // Buttons increment the hours, minutes, and seconds, respectively to Key3, Key2, and Key1 if(clk_modify == 1 && alarm_modify == 0 && alarm == 0){ // Handle if a key was pressed if (edge_capture) { handle_key_press_time(); } } // Allow user to change the alarm if SW1 is up if((sw_values & MASK_1) == 0x00000002){ alarm_modify = 1; alt_up_character_lcd_set_cursor_pos(char_lcd_dev, 0, 1); alt_up_character_lcd_string(char_lcd_dev, bot_row); } else{ alarm_modify = 0; alt_up_character_lcd_set_cursor_pos(char_lcd_dev, 0, 1); alt_up_character_lcd_string(char_lcd_dev, " "); } // Buttons increment the hours, minutes, and seconds, respectively to Key3, Key2, and Key1 if(alarm_modify == 1 && clk_modify == 0 && alarm == 0){ // Handle if a key was pressed if (edge_capture) { handle_key_press_alarm_set(); } } // Check if alarm should go off yet if(hours == alarm_hours && minutes == alarm_minutes && seconds == 0){ alarm = 1; init_timer_1(&half_second); } // While alarm is going off if( alarm == 1 ){ if (half_second % 2) { // Turn hex on hex_on(); } else { // Turn hex off hex_off(); } if( edge_capture) { handle_key_press_alarm(); } } else { stop_timer_1(); } // Check SW16 for "AM_PM" enable or "24" mode enable // If the switch is enabled, then we turn on 24 hour mode // Else we turn on AM / PM Mode // TODO: Optimize so that it doesn't assign something every loop cycle. Maybe we could slim it down if((sw_values & MASK_16) == MASK_16 ) { am_pm_mode = 0; } else { am_pm_mode = 1; } // Update the clock if (tenths != old_tenths) { // Call the util.h function to update the time update_time(top_row, &old_tenths, &tenths, &seconds, &minutes, &hours, &day, &month, &year, am_pm_mode, 0); // Write the updated time to the display alt_up_character_lcd_set_cursor_pos(char_lcd_dev, 0, 0); alt_up_character_lcd_string(char_lcd_dev, top_row); } } return 0; }