IF statement doesn't work (using Arduino, Firmata, controlP5)
in
Integration and Hardware
•
4 months ago
I'm using Processing 1.5.1 on a Windows7-64bit machine.
- import controlP5.*;
- import processing.serial.*;
- import cc.arduino.*;
- Arduino arduino;
- ControlP5 cp5;
- int ledPin = 12;
- color mycolor = color(0);
- int sliderValue = 100;
- boolean sliderValueLargetThanHundred = false;
- void setup() {
- arduino = new Arduino(this, Arduino.list()[0], 57600);
- arduino.pinMode(ledPin, Arduino.OUTPUT);
- size(700, 400);
- cp5 = new ControlP5(this);
- cp5.addSlider("sliderValue")
- .setPosition(20, 200)
- .setRange(0,255)
- .setSize(255, 20)
- .setValue(100)
- ;
- }
- void draw() {
- background(mycolor);
- if(sliderValue > 100) arduino.digitalWrite(ledPin, Arduino.HIGH);
- else arduino.digitalWrite(ledPin, Arduino.LOW);
- }
- public void sliderValue(int value) {
- sliderValueLargetThanHundred = value > 100;
- }
When I run this code, even if i change sliderValue by dragging slider, there is no change to the LED connected to Arduino board.
If I use a boolean variable(sliderValueLargerThanHundred) instead of "sliderValue > 100", the light is turned on and off as I expected.
Why does that IF statement only works with a boolean variable?
1