Go Down

Topic: Millis, repeat code. how to make it work????? (Read 1 time) previous topic - next topic

CrossRoads

Need to reset x for the next pass thru also, forgot add that:

while (x <7){
your code that repeats

x=x+1;
}
x=0; // reset for next pass thru loop.
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Theelectronicguy

Thanks for the quick replies.

I tried it and it worked. Now I just want to know how to run simultaneously a code that turns on or off a led based on the value of the sensor and I can get on with my life :). I don't know how to use the blinkwithuthdelay example with an "if" statement.

CrossRoads

Analog sensor? Digital sensor? where do you want it to turn on/off - outside of the while loop?
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Theelectronicguy

Analog sensor.

I figured it out.

Thanks for all the help.

Joonazan

#9
Mar 03, 2011, 08:57 pm Last Edit: Mar 03, 2011, 08:59 pm by Joonazan Reason: 1
I have written a library that should help with this.
Try something like this:
Code: [Select]

#include <"Timing.h">

class StateMachine
{
 int state = 1;
 public:
 void next()
 {
   switch(state){
   case 1: digitalWrite(13,HIGH); events.add(1000,next); break;
   case 2: digitalWrite(13,LOW); events.add(1000,next); break;
   default: state = 1;}
   state++;
 }
};

// You also need some code that uses this class


For example the for loop would be replaced with:
Code: [Select]

if(state < 4){something; state++;}


EDIT: You posted while I was writing. Use this code if you add another thing with delays.

Go Up