Use Millis instead of Delay


hi, how can use millis instead of delay in code?


code: [select]

const int button = 2;
const int led = 8;
const int pump = 9;

int buttonpush = 0;
int buttonstate = 0;
int lastbuttonstate = 0;

void setup() {
  // put setup code here, run once:
pinmode(led, output);
pinmode(button, input);
pinmode(pump, output);
serial.begin(9600);
}

void loop() {
  // put main code here, run repeatedly:

  buttonstate = digitalread(button);

  if (buttonstate != lastbuttonstate) {

    if (buttonstate == high) {
      buttonpush++;
      serial.println("on");
      serial.print("number of button pushes:  ");
      serial.println(buttonpush);
    } else {
      // if current state low button
      // wend on off:
      serial.println("off");
      buttonpush++;
    }
    // delay little bit avoid bouncing
    delay(50);
  }

  lastbuttonstate = buttonstate;
 
if (buttonpush == 1) {
  digitalwrite(led, high);
  delay(50);
  digitalwrite(led, low);
  delay(50);
} else {
  digitalwrite(led, low);
  digitalwrite(pump, low);
 
}
if (buttonpush == 2) {
  delay(500);
  digitalwrite(pump, high);
  delay(3000);
  digitalwrite(pump, low);
  buttonpush--;
  buttonpush--;
  serial.println("done");
  }
}




Arduino Forum > Using Arduino > Programming Questions > Use Millis instead of Delay


arduino

Comments

Popular posts from this blog

Flip address is out of range arduino uno r3

Arduino Uno not uploading

Indesign and MathType fonts