blinking an led using v2

the blink led program demonstrates persistence of vision (pov) through serial communication

by controlling the frequency of flashing, the led gets to a point where it appears to be on even though we know it is going on and off. what frequency is this. investigate by entering the frequency as a number between 1-50Hz

the only thing you need to program a v2 controller’s atmega side is asb-micro usb cable similar to that used in an arduino

power your v2 controller board using a 9-24v dc power adapter. connect the micro usb end to the v2 controller and connect the other end to your computers usb port. remember to flick the programming switch on the v2 board to the atmega side.  using your arduino ide, compile and upload the  blink program bellow as you would in an arduino. remember to set your arduino board setting to 2560 mega. led 13 is connected on the board.

/*

  Blink

  Turns on an LED on then off, repeatedly based on the frequency

  controlled by a number that the user enters between 1 and 50hz.

  This program demonstrates persistence of vision (pov).

 */



// Pin 13 has an LED connected on most Arduino boards.

// give it a name:

int led = 13;

long baudrate=38400;

int frequency = 1; //hz



// the setup routine runs once when you press reset:



void setup() {                

  // initialize the digital pin as an output.

  Serial.begin(baudrate);

  pinMode(led, OUTPUT);     

}



// the loop routine runs over and over again forever:

void loop() {



    // if there's any serial available, read it:

    while (Serial.available() > 0) {



        // look for the next valid integer in the incoming serial stream:

        frequency = Serial.parseInt(); 

        // look for the newline. That's the end of your sentence:

        if (Serial.read() == 'n') {

            // constrain the values to 0 - 255 and invert

            frequency = constrain(frequency, 0, 50);

        }        

    }

    int timer = 60/(2*frequency);



    digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)

    delay(timer);               // wait for a second

    digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW

    delay(timer);               // wait for a second

}