Hello everybody,
I have attached a button (roller lever switch?) to my robot starter kit and tested it with the RGB LED. This only partially works.
What do I have to change?
greetings!
Taster1|364x217
Taster, roller lever switch
koma1965
#1
koma1965
#3
Hello,
sorry, how do I insert a picture???
I copied the code out of the Mblock from the Arduino IDE.
I also tested without waiting.
Greetings!
#include <Arduino.h>
#include <Wire.h>
#include <SoftwareSerial.h>
#include <MeOrion.h>
double angle_rad = PI/180.0;
double angle_deg = 180.0/PI;
MeLimitSwitch sw_8_2(8,2);
MeRGBLed rgbled_6(6, 4);
void setup(){
}
void loop(){
if(sw_8_2.touched()){
_delay(0.5);
rgbled_6.setColor(0,20,20,20);
rgbled_6.show();
}
if(sw_8_2.touched()){
_delay(0.5);
rgbled_6.setColor(0,0,0,0);
rgbled_6.show();
}
_loop();
}
void _delay(float seconds){
long endTime = millis() + seconds * 1000;
while(millis() < endTime)_loop();
}
void _loop(){
}
Andreas
#4
So what is the code supposed to do?
With the wait as in above, it will:
Check if the switch is pressed, and if yes, turn on the LED for 0,5 sec and then turn it off if the switch is still pressed. If the switch is no longer pressed after 0.5 sec, the LED will stay on.
Without a wait, it would:
Check if the switch is pressed, and if yes, turn on the LED for a millisecond and then turn it off again. That would barely be visible.
If the intent is just to flash the LED strip when the limit switch is pressed, the I’d suggest something like: