Go Down

Topic: Sketch help with "If..else" statements and GoBetWino (Read 351 times) previous topic - next topic

sdl5e

I have built a system with 5 slotted switch sensors that are currently individually driving 5 LEDs.   When none of the sensors are blocked, all 5 LEDs are on.  As each sensor is sequentially blocked, the 5 LEDs turn off sequentially.  What I am trying to do is to have 6 different images project on a computer screen depending on how many of the sensors are blocked. 

If I connect each of the 5 sensors to PINS 1-5 (and for argument sake when the sensor is not blocked, it produces an analog value > 50 and when blocked the signal is <50), I think the following "logic" would accomplish what I want:

IF PIN 1>50 and 
IF PIN 2>50 and
IF PIN 3>50 and
IF PIN 4>50 and
IF PIN 5>50 then display PHOTO1.JPG

IF PIN 1<50
IF PIN 2>50 and
IF PIN 3>50 and
IF PIN 4>50 and
IF PIN 5>50 then display PHOTO2.JPG

IF PIN 1<50,
IF PIN 2<50 and
IF PIN 3>50 and
IF PIN 4>50 and
IF PIN 5>50 then display PHOTO3.JPG

IF PIN 1<50
IF PIN 2<50 and
IF PIN 3<50 and
IF PIN 4>50 and
IF PIN 5>50 then display PHOTO4.JPG

IF PIN 1<50
IF PIN 2<50 and
IF PIN 3<50 and
IF PIN 4<50 and
IF PIN 5>50 then display PHOTO5.JPG

IF PIN 1<50 and   
IF PIN 2<50 and
IF PIN 3<50 and
IF PIN 4<50 and
IF PIN 5<50 then display PHOTO6.JPG

I have played around with GoBetWino and should be able to open the 6 image files on my computer, but I need to get the Arduino sketch setup properly. 

Should I use and if..else argument?  Could someone point me in the right direction? Any help would be appreciated!

Thank you

Goofballtech

#1
Dec 04, 2012, 03:13 am Last Edit: Dec 04, 2012, 03:31 am by Goofballtech Reason: 1
If the code works like you hope and the "display" command work as you think it will (very unlikely) it would look like this for each comparison:

Code: [Select]
if (1>50 && 2>50 && 3>50 && 4>50 && 5>50)
{
display photo1.jpg;
}


If this is your whole sketch though you are missing some stuff like:

Code: [Select]
#includeYourLibraryThatContainsDisplay

setup (){

}

loop () {

}

Goofballtech

The more i think about it the more i need to know more of what you are trying to do and if this is all your code. You can do multiple things at once since they are all checking the same thing..... so you could do this.

Code: [Select]
if (1>50 && 2>50 && 3>50 && 4>50 && 5>50)
{
display photo1.jpg;
display photo2.jpg;
display photo3.jpg;
display photo4.jpg;
display photo5.jpg;
display photo6.jpg;
}


But i would advise assigning names to your pins because using the pin numbers gets to be frustration. In any case to get reading you have to call a function that does so.

Code: [Select]
const byte sensorOne = 1;  // sensor one is connected to pin one
int sensorOneVal;  // create variable to hold the incoming value

setup(){
pinMode(sensorOne, INPUT); // set pin one as an input
}

loop(){
sensorOneVal = analogRead(sensorOne); // read the value of sensor one and store it to sensorOneVal

 if (sensorOneVal > 50)  // see if the sensor value was above 50
 {
 display photo1.jpg  // display the photo, whatever that means....
 }

}


My advice, if you just read what i put in that code block and have no idea whats happening..... start here and read lots more!

Go Up