Pages: [1]   Go Down
Author Topic: Sketch help with "If..else" statements and GoBetWino  (Read 271 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

South Louisiana
Offline Offline
Full Member
***
Karma: 0
Posts: 178
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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:
#includeYourLibraryThatContainsDisplay

setup (){

}

loop () {

}
« Last Edit: December 03, 2012, 09:31:01 pm by Goofballtech » Logged

South Louisiana
Offline Offline
Full Member
***
Karma: 0
Posts: 178
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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:
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!
Logged

Pages: [1]   Go Up
Jump to: