Hi,
I have been working on my project and I want the loop to run when you push the button once. I want it to stop when you push the button again. I got the code working for the vibration motor but for some reason when i push the button the RGB LED switches to white instead of red - orange - green. Does anybody know what is going wrong?
//
#include <FastLED.h>
//connections of the ChainableLED
#define DATA_PIN 5
#define CLOCK_PIN 4
#define NUM_LEDS 1
int MoPin = 3;
boolean state = false;
int buttonpin;
//an array to hold the led data
CRGB leds[NUM_LEDS];
void setup() {
//start the led library
FastLED.addLeds<P9813, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
buttonpin=5;
pinMode(buttonpin,INPUT_PULLUP);
}
void loop() {
while(state==false){
if(digitalRead(buttonpin)==HIGH){
// Turn the LED to Green
leds[0].setRGB( 0, 255, 0);
FastLED.show();
delay(5000);
//vibrate
digitalWrite(MoPin,HIGH);
delay(500);
digitalWrite(MoPin,LOW);
// Turn LED to orange
leds[0].setRGB( 255, 50, 0);
FastLED.show();
delay(5000);
//vibrate
digitalWrite(MoPin,HIGH);
delay(500);
digitalWrite(MoPin,LOW);
// turn LED to red
leds[0].setRGB( 255, 0, 0);
FastLED.show();
delay(5000);
state=false;
}
}
}
code_probeersel.ino (980 Bytes)