Statements and Loops
in
Contributed Library Questions
•
7 months ago
So I have a sketch using Arduino Firmata receiving button input. All is well at that end.
I am trying to construct my loops as follows:
When button A == pressed, trigger imageTwo and STAY at imageTwo.
when button B ==pressed, trigger imageThree, and STAY at imageThree.
etc, etc.
code below:
- import processing.serial.*;
- PImage imgHome;
- PImage imgMil;
- PImage imgCiv;
- import cc.arduino.*;
- Arduino arduino;
- int button8=8;
- int button7=7;
- int button6=6;
- //this reads button states
- int state=0;
- int state2=0;
- int state3 =0;
- int Width = 1920;
- int Height = 1080;
- void setup() {
- size(Width,Height); //this was size requested for screen
- imgHome = loadImage("Home.jpg");
- imgMil = loadImage("Military.jpg");
- imgCiv = loadImage("Civilian.jpg");
- //size (displayWidth,displayHeight); //this adjusts toyour monitor
- arduino = new Arduino(this, Arduino.list()[0], 57600);
- arduino.pinMode(button8, Arduino.INPUT);
- arduino.pinMode(button7, Arduino.INPUT);
- arduino.pinMode(button6, Arduino.INPUT);
- }
- void draw() {
- state=arduino.digitalRead(button8);
- state2=arduino.digitalRead(button7);
- //println(state); //reads button states in serial monitor
- //println(state2);
- switch(state){
- //compare states and trigger images
- case 1:
- image(imgHome, 0,0);
- case 0:
- image(imgHome, 0,0);
- break;
- }
- switch(state2){
- case 1:
- image(imgMil, 0,0);
- case 0:
- image(imgMil, 0,0);
- break;
- }
- if (state==Arduino.LOW && state2==Arduino.LOW){
- image(imgCiv, 0,0);
- }
- }
1