Hi guys,
I'm starting to read this book ("Arduino - A quick-start guide"), and I am now working on the exercise where I have to give it more commands other than turn LED on/off.
I am attempting to make it so when I give it another command, it sets off on a loop where it just keeps blinking until I give it the command 4 - where it stops and just stays that way, and as you can see at the very beginning of the code, it simply does not work - prints the line just fine, but that's as far as it goes.
Now, I am waaay too used to Python, and when I try to work with while loops, it gives me errors. So I googled it, read about it, and here's how I have it so far-
//Project b.1 - command an LED from a serial port.
//Status - get the stupid while loop and function working.
//It does not seem to work for some reason.
const unsigned int ledPin = 13;
void setup(){
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void blinkmode(){
int blinkmodeon = 1;
while (blinkmodeon == '1')
{
if (Serial.available() > 0){
int command = Serial.read();
if (command == '4') {
blinkmodeon == 0;
}
else {
digitalWrite(ledPin, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
delay(500);
}
}
}
}
void loop(){
if (Serial.available() > 0) {
int command = Serial.read();
if (command == '1') {
digitalWrite(ledPin, HIGH);
Serial.println("Led is on.");
}
else if (command == '2'){
digitalWrite(ledPin, LOW);
Serial.println("Led is off.");
}
else if (command == '3'){
Serial.println("Blink mode started. Send command '4' to stop.");
blinkmode();
}
else {
Serial.println("Huh?");
}
}
}
Biggest issue of mine - parameters. How do they work and how can I use them? I keep seeing thousands of examples, but I never really got to understand them fully
Any help would be appreciated.