Go Down

Topic: if statement not working on new Uno board (Read 535 times) previous topic - next topic

0IIIIIII0

I am thinking I just have a bad board.  I just bought it and am going through a tutorial to learn how to use it.  This is just making the led on the board blink with an increasing on and off time.  That part works, but once I add an "if" statement to reset the counter once the delay has reached 3000 the delay period no longer increases, it continues to blink fast.  I've tried increasing the trigger from 3000 to 100000 without any difference.  I've reversed it like this: if (10000 < delayPeriod) delayPeriod = 100 and it hasn't made a difference.  Below is what I'm trying to use:

Quote

int ledPin = 13;
int delayPeriod = 100;

void setup()
{
  pinMode(ledPin, OUTPUT);
}

void loop()
{
  digitalWrite(ledPin, HIGH);
  delay(delayPeriod);
  digitalWrite(ledPin, LOW);
  delay(delayPeriod);
  delayPeriod = delayPeriod + 100;
  if (delayPeriod = 100000) delayPeriod = 100;
  
}



I have also tried:  if (delayPeriod > 10000)
{
delayPeriod = 100
}

and there wasn't any difference.  Am I missing something or could it just be a bad board?

spycatcher2k

if (delayPeriod = 100000) delayPeriod = 100;

if (delayPeriod == 100000) delayPeriod = 100;
Mrs Drew
-=-
http://www.uk-pcb.co.uk - UK PCB Fab Company
I will design & code for you, but I will also charge you (PM me)
If you don't like my answers, realize : I'm not being cheeky, I'm Just trying to prompt you to use your own brain/google etc.

CrossRoads

int's only go to 65,535.

try
unsigned long delayperiod;

Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

0IIIIIII0

Thank you both.  After using the double = sign it started working, even using the greater than sign works now.  if delayPeriod > 3000 was not working before, but now it does.

Go Up