int main (void) { save_power(); USART0Init(); buttons_init(); tone_init(); int useless_steps = 0; int state = STATE_GO_OFF; while (1) { if (useless_steps >= 1000) { useless_steps = 0; state = STATE_GO_OFF; } if (state == STATE_GO_OFF) { state = STATE_IS_OFF; USART0SendString(""); USART0BacklightOff(); deep_sleep(); } tick(); if (toggle_state() == 0) { useless_steps = 0; USART0BacklightOn(); write_next_chore(); while (toggle_state() == 0) { tick(); } // Wait for button to be released int seconds = 0; int miliseconds = 0; while (1) { if (toggle_state() == 0) { state = STATE_GO_OFF; notone(); break; } if (timer_state() == 0) { miliseconds = 0; seconds = 0; notone(); } miliseconds++; if (miliseconds >= 1000) { seconds++; miliseconds = 0; } if (seconds == TIMER_LENGTH) { tone(4400); } else if (seconds > 1000) { seconds = (TIMER_LENGTH + 1); } tick(); } } else { useless_steps++; } } }
int main(void) { int i; for (i = 0; i < 800; i++) { receivedData[i] = 0; } // init IO DDRB |= (1 << OUTPUT_PIN); // Set the output pin DDRC &= ~(1 << INPUT_PIN); // Set the input pin PORTC |= (1 << INPUT_PIN); // Enable pull-up resistor /*TCCR0A |= (1 << WGM01); // Set the Timer Mode to CTC OCR0A = 0x7D; // Set the value that you want to count to TIMSK0 |= (1 << OCIE0A); //Set the ISR COMPA vect sei(); //enable interrupts TCCR0B |= (1 << CS02); // set prescaler to 256 and start the timer*/ /* USART INIT START */ USART0Init(); stdout =& usart0_output; stdin =& usart0_input; /* USART INIT STOP */ SPIInit(); // Init the SPI bus //char input[100] = "Now, this is a story all about how My life got flipped-turned upside down"; char input[100] = ""; printf("\n\n\n\nSTART CODE WITH THIS INPUT: %s\n\n", input); // Print the input string uint8_t* dataToSend = fillDataArray(input); // Convert data to base2 unsigned int time; time = (1000 / OUTPUT_BAUDRATE) * dataLength; printf("Baudtime: %i\n", 1000/OUTPUT_BAUDRATE); printf("Time needed to send: %i ms\n", time); sendData(dataToSend); printf("datalength: %i\n", dataLength); char* received = convertToData(receivedData, dataLength); // Convert base2 to data if (received[0] == -1) { printf("Error detected...\n"); } else { printf("\nReceived data: %s\n\n", received); // Print the received data } printf("Entering loop now....\n"); PORTB &= ~(1 << OUTPUT_PIN); while (1) { // Main loop } }