Hello! I have a problem with my code, and I I`m a newbie in in the language the Arduino use.
I just wanted to make a LED show, to test the Arduino.
I tried to make a binary counter, witch have been successfully.
Then I tried to make it "mirrored". But seems to not work so well.
Original code (works!):
/*
Binary counter by BlackPaw
created 2014
by BlackPaw
created 17 Jan 2014
modified 20 Jan 2014
by BlackPaw
*/
// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 12; // the number of the pushbutton pin
const int ledPin1 = 2; // the number of the LED1 pin
const int ledPin2 = 3; // the number of the LED2 pin
const int ledPin3 = 4; // the number of the LED3 pin
const int ledPin4 = 5; // the number of the LED4 pin
const int ledPin5 = 6; // the number of the LED5 pin
const int ledPin6 = 7; // the number of the LED6 pin
const int ledPin7 = 8; // the number of the LED7 pin
const int ledPin8 = 9; // the number of the LED8 pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
int led1 = 1;
int led2 = 2;
int led3 = 3;
int led4 = 4;
int led5 = 5;
int led6 = 6;
int led7 = 7;
int led8 = 8;
void setup() {
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
pinMode(ledPin5, OUTPUT);
pinMode(ledPin6, OUTPUT);
pinMode(ledPin7, OUTPUT);
pinMode(ledPin8, OUTPUT);
pinMode(buttonPin, INPUT);
}
void loop(){
start:
led1 = digitalRead(ledPin1);
if (led1 == LOW) {
digitalWrite(ledPin1, HIGH);
delay(250);
goto start;
}
else {
digitalWrite(ledPin1, LOW);
}
led2 = digitalRead(ledPin2);
if (led2 == LOW) {
digitalWrite(ledPin2, HIGH);
delay(250);
goto start;
}
else {
digitalWrite(ledPin2, LOW);
}
led3 = digitalRead(ledPin3);
if (led3 == LOW) {
digitalWrite(ledPin3, HIGH);
delay(250);
goto start;
}
else {
digitalWrite(ledPin3, LOW);
}
led4 = digitalRead(ledPin4);
if (led4 == LOW) {
digitalWrite(ledPin4, HIGH);
delay(250);
goto start;
}
else {
digitalWrite(ledPin4, LOW);
}
led5 = digitalRead(ledPin5);
if (led5 == LOW) {
digitalWrite(ledPin5, HIGH);
delay(250);
goto start;
}
else {
digitalWrite(ledPin5, LOW);
}
led6 = digitalRead(ledPin6);
if (led6 == LOW) {
digitalWrite(ledPin6, HIGH);
delay(250);
goto start;
}
else {
digitalWrite(ledPin6, LOW);
}
led7 = digitalRead(ledPin7);
if (led7 == LOW) {
digitalWrite(ledPin7, HIGH);
delay(250);
goto start;
}
else {
digitalWrite(ledPin7, LOW);
}
led8 = digitalRead(ledPin8);
if (led8 == LOW) {
digitalWrite(ledPin8, HIGH);
delay(250);
goto start;
}
else {
digitalWrite(ledPin8, LOW);
delay(250);
}
}
and here is the mirrored code (does not work):
/*
Binary counter by BlackPaw
created 2014
by BlackPaw
created 17 Jan 2014
modified 20 Jan 2014
by BlackPaw
*/
// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 12; // the number of the pushbutton pin
const int ledPin1 = 2; // the number of the LED pin
const int ledPin2 = 3;
const int ledPin3 = 4;
const int ledPin4 = 5;
const int ledPin5 = 6;
const int ledPin6 = 7;
const int ledPin7 = 8;
const int ledPin8 = 9;
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
int led1 = 1;
int led2 = 2;
int led3 = 3;
int led4 = 4;
int led5 = 5;
int led6 = 6;
int led7 = 7;
int led8 = 8;
void setup() {
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
pinMode(ledPin5, OUTPUT);
pinMode(ledPin6, OUTPUT);
pinMode(ledPin7, OUTPUT);
pinMode(ledPin8, OUTPUT);
pinMode(buttonPin, INPUT);
}
void loop(){
start2:
led8 = digitalRead(ledPin8);
if (led8 == LOW) {
digitalWrite(ledPin8, HIGH);
delay(500);
goto start2;
}
else {
digitalWrite(ledPin8, LOW);
}
led7 = digitalRead(ledPin7);
if (led7 == LOW) {
digitalWrite(ledPin7, HIGH);
delay(500);
goto start2;
}
else {
digitalWrite(ledPin7, LOW);
}
led6 = digitalRead(ledPin6);
if (led6 == LOW) {
digitalWrite(ledPin6, HIGH);
delay(500);
goto start2;
}
else {
digitalWrite(ledPin6, LOW);
}
led5 = digitalRead(ledPin5);
if (led5 == LOW) {
digitalWrite(ledPin5, HIGH);
delay(500);
goto start2;
}
else {
digitalWrite(ledPin5, LOW);
}
led4 = digitalRead(ledPin4);
if (led4 == LOW) {
digitalWrite(ledPin4, HIGH);
delay(500);
goto start2;
}
else {
digitalWrite(ledPin4, LOW);
}
delay(500);
}
I cannot seem to find the error, tried to remake it over and over again.
I know there is many other ways to do this, but I only wanted to make a simple program to understand Arduino programming language.
Here`s a picture of the wireupp:
Regards - BlackPaw