Showing posts with label led. Show all posts
Showing posts with label led. Show all posts

Wednesday, March 20, 2013

Communication test

Exercise 0: Communication test.

Explain.

A serial of leds, will switch on and switch off continuously, in both directions, the delay between switch can be modified using two buttons.
An the delay value will send the cubieboard and displayed.


Code at the arduino.
.....
void setup()
{

//Initiate the serial communications at the arduino
  Serial.begin(115200);

//Digital pins for output
  for (int x=0; x<5;x++)
  {
    pinMode(ledPin[x],OUTPUT);
  }

// Digital pins for Input
  pinMode(btnUP,INPUT); 
  pinMode(btnDOWN,INPUT);
  changeTime =millis();
}

// Main program in a continuous loop
void loop()
{
  if ((millis() -changeTime) > ledDelay)
  {
    changeLED();
    changeTime= millis();
  }
  if (digitalRead(btnUP))
  {

//Serial print will be part of a function to use a protocol
    Serial.println(ledDelay++);
    delay(20);
        if (ledDelay >200) ledDelay =200;
  }

...........

void changeLED()
{
  //switch off all the leds
  for (int x =0; x<5;x++)
  {
    digitalWrite(ledPin[x],LOW);
  }
  digitalWrite(ledPin[currentLed],HIGH);
  currentLed += direction;
  if (currentLed == 4) {direction = -1;}
  if (currentLed == 0) {direction = 1;} 
}


Note: In the "Serial.println(value) will be used to make a function to control the protocol between arduino and cubieboard

To see if the cubieboard can receive the data I use the information that I find here : http://linux-sunxi.org/Cubieboard/TTL

stty -F /dev/ttyS0 -crtscts  
cu -s 115200 -l /dev/ttyS0
 

I know that the circuit is very simple, and even one of the worst I've ever made, but is just to see the idea.

If any one has any idea, or doubt, please share, I made this to learn and share.