need help

Hi,i just started learning how to write code and don't know where i am going wrong.I do good until i add 4 inputs,what do you all think
thanks tom

/*

4 inputs with with (and &&) and 2 outputs

*/

// set pin numbers:
int buttonPin1 = 2; /*come in from rovio
int buttonPin2 = 3; *
int buttonPin3 = 4; *
int buttonPin4 = 5; /
int ledPin = 10; // out to wheels
int ledpin = 8; //out to wheels
// variables will change:
int buttonState1 = 0; /
variable for reading rovio status
int buttonState2 = 0; *
int buttonState3 = 0; *
int buttonState4 = 0; */
void setup() {
// initialize the pin as an output and input
pinMode(10, OUTPUT);
pinMode(8, OUTPUT);
pinMode(3, INPUT);
pinMode(4, INPUT);
pinMode(5, INPUT);
pinMode(2, INPUT);
}

void loop(){
// read rovio input
buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
buttonState3 = digitalRead(buttonPin3);
buttonState4 = digitalRead(buttonPin4);

// if it is, then it is HIGH:
if (buttonState1 == HIGH && buttonState2 == HIGH){

// turn LED on:
digitalWrite(ledPin = 10, HIGH);
}
else {
// turn LED off:
digitalWrite(ledPin = 10, LOW);
}

if (buttonState3 == HIGH && buttonState4 == HIGH) {
// turn LED on:
digitalWrite(ledPin = 8, HIGH); //turn led on
}
else {

digitalWrite(ledPin = 8, LOW);
}
}

How are buttons wired up?
Or are they not really buttons, but 0/5V output from the rovio?

Fix these type of statements:
// turn LED on:
digitalWrite(ledPin = 10, HIGH); << do not add the ' =10' here

You gave all the pins names, why not use them here?
pinMode(10, OUTPUT);
pinMode(8, OUTPUT);
pinMode(3, INPUT);
pinMode(4, INPUT);
pinMode(5, INPUT);
pinMode(2, INPUT);

also you could make your output pin names more clear:
ledPin vs ledpin
this will help to prevent this:
// turn LED on:
digitalWrite(ledPin = 10, HIGH);
& later on
digitalWrite(ledPin = 8, HIGH);

But back to the basic question - what is driving the buttons? Is it an actively driven signal, or a button with a pullup or pulldown resistor that then needs debouncing?

it is o/5volt (low/high) coming out of rovio.I am just learning how to do this,i can program ladder logic very well but this is all new.i am not sure what this means i will look it up << do not add the ' =10' here
as for names i was trying to keep it simple while i am learning. thanks for help any more advise will be very helpful
tom

In your sketch you used:

digitalWrite(ledPin = 10, HIGH);

This is bad style. You should use: digitalWrite(10, HIGH);

Or better still, use a named pin: #define launchPin = 10;

You could then use: digitalWrite(launchPin, HIGH);

This latter example is the best in case you ever have to change pin wiring you only have to update your sketch at the define line and all the statements that use that pin name will automatically track that change when you recompile.

Lefty

Make these changes to help prevent future confusion:
int ledPin10 = 10; // out to wheels
int ledPin8 = 8; //out to wheels

Similarly, change these:
pinMode(10, OUTPUT); --> pinMode(ledPin10, OUTPUT);
pinMode(8, OUTPUT); --> pinMode (ledPin8, OUTPUT);
pinMode(3, INPUT); --> pinMode (buttonPin3, INPUT);
pinMode(4, INPUT); --> pinMode (buttonPin4, INPUT);
pinMode(5, INPUT); --> pinMode (buttonPin5, INPUT);
pinMode(2, INPUT); --> pinMode (buttonPin2, INPUT);

and then change the names here to match:
// turn LED on:
digitalWrite(ledPin = 10, HIGH); --> ledPin10, HIGH
}
else {
// turn LED off:
digitalWrite(ledPin = 10, LOW); --> ledPin10, LOW
}

if (buttonState3 == HIGH && buttonState4 == HIGH) {
// turn LED on:
digitalWrite(ledPin = 8, HIGH); //turn led on --> ledPin8, HIGH
}
else {
digitalWrite(ledPin = 8, LOW); --> ledPin8, LOW
}

CR....yellow text on light grey background just doesn't work.... :smiley:

Sorry, was trying to highlight, got the wrong thing I guess. Let me see if I can edit.

no more test ??
red shadow >> not seeing any difference with shadow
red glow this just looks blurry

We need the highlight option back.

ok i still get error here is the new one

/*

4 inputs with with (and &&) and 2 outputs

*/

// set pin numbers:
int rredPin1 = 2; /come in from rovio
int rblackPin2 = 3; *
int lredPin3 = 4; *
int lblackPin4 = 5; *
int fwheelPin = 10; // out to wheels
int rwheelpin = 8;
// variables will change:
int rredState1 = 0; /
variable for reading rovio status
int rblackState2 = 0; *
int lredState3 = 0; *
int lblackState4 = 0; */
void setup() {
// initialize the pin as an output and input
pinMode(10, OUTPUT);
pinMode(8, OUTPUT);
pinMode(3, INPUT);
pinMode(4, INPUT);
pinMode(5, INPUT);
pinMode(2, INPUT);
}

void loop(){
// read rovio input
rredState1 = digitalRead(rredPin1);
rblackState2 = digitalRead(rblackPin2);
lredState3 = digitalRead(lredPin3);
lblackState4 = digitalRead(lblackPin4);

// if it is, then it is high
if (rredState1 == HIGH && rblackState2 == HIGH){

// turn LED on:
digitalWrite(fwheelPin, HIGH);
}
else {
// turn LED off:
digitalWrite(fwheelPin1, LOW);
}

if (lredState3 == HIGH && lblackState4 == HIGH) {
// turn LED on:
digitalWrite(rwheelPin, HIGH);
}
else {

digitalWrite(rwheelPin, LOW);
}
}

bobo_bot_wont_work.cpp: In function 'void loop()':
bobo_bot_wont_work:32: error: 'rredState1' was not declared in this scope
bobo_bot_wont_work:33: error: 'rblackState2' was not declared in this scope
bobo_bot_wont_work:33: error: 'rblackPin2' was not declared in this scope
bobo_bot_wont_work:34: error: 'lredState3' was not declared in this scope
bobo_bot_wont_work:34: error: 'lredPin3' was not declared in this scope
bobo_bot_wont_work:35: error: 'lblackState4' was not declared in this scope
bobo_bot_wont_work:35: error: 'lblackPin4' was not declared in this scope
bobo_bot_wont_work:41: error: 'fwheelPin' was not declared in this scope
bobo_bot_wont_work:45: error: 'fwheelPin1' was not declared in this scope
bobo_bot_wont_work:52: error: 'rwheelPin' was not declared in this scope
bobo_bot_wont_work:56: error: 'rwheelPin' was not declared in this scope

the line where you have
/*
everything between that and
*/
is considered a comment.
Fix that stuff up.
If you want a comment on an indivual line, put // and then your comment

ok found one fix /* insted of //* but now cnat find fix for
56: error: 'rwheelPin' was not declared in this scope

rwheelpin is a different variable than this rwheelPin, make them match

thank for all your help it workes now.Like i said i use to program robots in a dvd factory with ladder logic and flow charts when i was young now i am old have to learn all over a new way to have fun with my toys,it not all mechanical any more

I understand. Just need to be careful with syntax and consistency. The other thing that will get you eventually is using = when == is needed:
if (x ==1) {action} will compare x to 1
if (x=1){action} will set x equal to 1

I still get caught by that one occasionally. Late night programming doesn't help :slight_smile: