After some tweaking for my own project it gives me a 'dynamic bar' but it starts running without me pressing any buttons.
What do I have to do to make the program react to my button presses? Consumption is the dynamic data to be put into a bar. The data will increase with every button press.
Hopefully some one can help me getting my program to work!
Thanks in advance!
Kim
Here is my code:
Arduino
...
int buttonRec = analogRead(buttons);
Serial.println(buttonRec);
if(buttonRec >= 745 && buttonRec <= 790) {
digitalWrite(ontbijtLED, HIGH);
updateValue(1, 1);
}
if(buttonRec >= 640 && buttonRec <= 710) {
analogWrite(lunchLED, 1023);
updateValue(1, 2);
}
if(buttonRec >= 450 && buttonRec <= 550) {
digitalWrite(dinerLED, HIGH);
updateValue(1, 3);
}
if(buttonRec >= 0 && buttonRec <= 50) {
digitalWrite(snackLED, HIGH);
updateValue(1, 4);
}
if(buttonRec > 800) {
digitalWrite(ontbijtLED, LOW);
analogWrite(lunchLED, 0);
digitalWrite(dinerLED, LOW);
digitalWrite(snackLED, LOW);
}
...
Processing
import processing.serial.*;
Serial myPort;
float weight = 60.3; // kg
float fatPercentage = 28; //%
float activityLevel = 1.2;
float leanMass = (weight * fatPercentage)/100;
float BMR = 370 + (21.6 * leanMass);
float personalEnergy = BMR * activityLevel;
float consumption = 0;
int data;
void setup() {
size(400, 400);
myPort = new Serial(this, Serial.list()[0], 9600);