#include // Load the ISRs #include "oulib_serial_buffered.h" /************************* * USB Serial Connection * *************************/ #define SERIAL_PORT 0 #define SERIAL_BAUD 38400 #define SERIAL_BUFFER_SIZE 40 /////////////////////////////////////////////////////////////////////////// // File pointer for USB connection FILE* fp0 = NULL; /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// int main(void) { char c; uint8_t i; // LED on the Arduino DDRB = 0x80; // Flash the LED a few times PORTB ^= 0x80; delay_ms(100); PORTB ^= 0x80; delay_ms(100); PORTB ^= 0x80; delay_ms(100); PORTB ^= 0x80; delay_ms(100); // Initialize the serial port connected to the USB cable fp0 = serial_init_buffered(SERIAL_PORT, SERIAL_BAUD, SERIAL_BUFFER_SIZE, SERIAL_BUFFER_SIZE); // Initialize all interrupts sei(); // Say 'hello' fprintf(fp0, "hello world\n\r"); while(1){ // Is there anything coming in from the serial port? if(serial_buffered_input_waiting(fp0)) { // Yes - read that character c = fgetc(fp0); // Report that we received this char fprintf(fp0, "Got character: %c %d\n\r", c, c); // Do something specific depending on which character it is switch(c) { case 'f': // Flash the LED fast for(i = 0; i < 8; ++i) { PORTB ^= 0x80; delay_ms(100); }; break; // Don't forget to terminate cases with breaks! case 's': // Flash the LED slow for(i = 0; i < 2; ++i) { PORTB ^= 0x80; delay_ms(1000); }; break; }; }; // Default flash rate PORTB ^= 0x80; delay_ms(250); }; return(0); }