Pages: [1]   Go Down
Author Topic: Help with my Project please  (Read 268 times)
0 Members and 1 Guest are viewing this topic.
Crewe
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have writen the following code to pulse an LED every two seconds

I am also using an XBee module and want to keep the LED on when I press a '1' on my PC to represent an input

But when I ran the programme the LED works untill I placed the XBee sheild on the Uno board and the LED will not work any ideas?

* test_fri_30.ino (0.56 KB - downloaded 5 times.)
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here is his code:

Code:
int led = 13;
byte pinState = 0;
int myData = 0;

void setup()
{               
  pinMode(led, OUTPUT);     
  Serial.begin(9600);
}

void loop()
{
  {
    digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
    delay(1000);               // for a second
    digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
    delay(2000);               // for two seconds
  }


  if(Serial.available() > 0){
    myData = Serial.read();
    if(myData == '1')
      digitalWrite(led, HIGH); //if '1' is pressed on computer LED on Arduino Uno board will light
  }
}

Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't see how that would work with our without the shield, because in the first part of loop you are turning the LED on and off anyway (whether or not you have serial input).
Logged

Crewe
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok, so how would I fix the programme.

The purpose of the circuit is an alarm type, I want an LED to blink every two seconds to prove the system is working

Upon an input from my computer the LED should be constant until the board is reset
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 553
Posts: 46300
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
  {
    digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
    delay(1000);               // for a second
    digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
    delay(2000);               // for two seconds
  }
What are these curly braces here for?

You have to decide under what conditions the LED should flash and under what conditions it should be on solid.

Personally, I'd use two different LEDs - one flashing to indicate that the system is working and one to indicate that it received a 1 from the serial port.

You might also want to consider some way to turn the LED off again.

The coding issues have nothing to do with the XBee or shield being in place or not.
Logged

Pages: [1]   Go Up
Jump to: