Hello
I am new to Arduino, & I have Arduino Mega 2560 board bought last month. I tried the basic examples listed in the software. I am trying to ON the 12 LEDs connected to Pins 2 - 13 with different sequences. I connected a button on pin 30. The idea is to switch ON the LEDs in different patrons, the patron selector is by the Push button. I found in the examples SWITCH Case2 & interlayed the sequences into it.
the problem i am experiencing is 1. Button input is reading or working. 2. If supply the selection through serial.read () the sequence works only one cycle. The codes are also attached.
Please help me.
[/
int inByte = 0;
void setup() {
// initialize serial communication:
Serial.begin(9600);
// initialize the LED pins:
for (int thisPin = 2; thisPin <= 13; thisPin++) {
pinMode(thisPin, OUTPUT);
}
pinMode(30, INPUT);
}
void loop() {
// read the sensor:
if (Serial.available() > 0)
//int inByte = Serial.read();*/
int inByte = 0;
int pinState = 30;
for (digitalRead(pinState) == HIGH; inByte >= 3; inByte = inByte++)
{
Serial.println("Button ON");
Serial.println(inByte);
}
if ( inByte >= 3 ) {
inByte == 0;
}
switch (inByte) {
case '0':{
for ( int thisPin = 2; thisPin <= 5; thisPin++) {
digitalWrite(thisPin, HIGH);
delay(100);
}
for ( int thisPin = 10; thisPin <= 13; thisPin++) {
digitalWrite(thisPin, HIGH);
delay(100);
}
for ( int thisPin = 2; thisPin <= 5; thisPin++) {
digitalWrite(thisPin, LOW);
delay(100);
}
for ( int thisPin = 6; thisPin <= 9; thisPin++) {
digitalWrite(thisPin, HIGH);
delay(100);
}
for ( int thisPin = 10; thisPin <= 13; thisPin++) {
digitalWrite(thisPin, LOW);
delay(100);
}
for ( int thisPin = 6; thisPin <= 9; thisPin++) {
digitalWrite(thisPin, LOW);
delay(100);
}
return;
}
case '1':{
for ( int thisPin = 2; thisPin <= 13; thisPin++){
digitalWrite(thisPin, HIGH);
delay(100);
}
for ( int thisPin = 2; thisPin <= 13; thisPin++){
digitalWrite(thisPin, LOW);
delay(100);
}
return;
}
case '2':{
for ( int thisPin = 2; thisPin <= 7; thisPin++) {
digitalWrite(thisPin, HIGH);
delay(100);
}
for ( int thisPin = 2; thisPin <= 7; thisPin++) {
digitalWrite(thisPin, LOW);
delay(100);
}
for ( int thisPin = 8; thisPin <= 13; thisPin++) {
digitalWrite(thisPin, HIGH);
delay(100);
}
for ( int thisPin = 8; thisPin <= 13; thisPin++) {
digitalWrite(thisPin, LOW);
delay(100);
}
return;
}
/* case 'd':
digitalWrite(5, HIGH);
break;
case 'e':
digitalWrite(6, HIGH);
break;*/
default:
// turn all the LEDs off:
for (int thisPin = 2; thisPin < 13; thisPin++) {
digitalWrite(thisPin, LOW);
}
}
}
]