Hello. I have a simple task that I want to do. I am using Arduino and bolt [just to log data]
-Have 4 buttons each assigned to a variable and then variable increments by +1 every time it is pressed. And there is an extra button to calculate and display the variable with the highest count.
What I want to do is just send the value of the 4 variables to the Bolt Cloud.
To send data I have referred to the Github page of bolt Arduino lib and used the bolt push data command.
Arduino code:-
int person_a = 0;
int person_b = 0;
int person_c = 0;
int person_d = 0;
int button1;
int button2;
int button3;
int button4;
int calculate;
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
#include <BoltIoT-Arduino-Helper.h>
#ifndef API_KEY
#define API_KEY "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx"
#endif
#ifndef DEVICE_ID
#define DEVICE_ID "BOLTxxxxxxxx"
#endif
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void setup()
{
Serial.begin(9600);
boltiot.Begin(Serial);
lcd.init();
lcd.backlight();
pinMode(7, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(11, INPUT_PULLUP);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void loop()
{
int button1 = digitalRead(7);
int button2 = digitalRead(5);
int button3 = digitalRead(4);
int button4 = digitalRead(3);
int calculate = digitalRead(11);
boltiot.processPushDataCommand(person_a, person_b, person_c, person_d);
if (button1 == 0) INCREASEa();
if (button2 == 0) INCREASEb();
if (button3 == 0) INCREASEc();
if (button4 == 0) INCREASEd();
if (calculate == 0) result();
delay(280);
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~FUNCTIONS~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
void INCREASEa()
{
lcd.clear();
lcd.print("Person A");
Serial.print("voted for person A");
person_a++;
Serial.print("\n");
}
void INCREASEb()
{
lcd.clear();
lcd.print("Person B");
Serial.print("voted for person B");
person_b++;
Serial.print("\n");
}
void INCREASEc()
{
lcd.clear();
lcd.print("Person C");
Serial.print("voted for person C");
person_c++;
Serial.print("\n");
}
void INCREASEd()
{
lcd.clear();
lcd.print("Person D");
Serial.print("voted for person D");
person_d++;
Serial.print("\n");
}
void result()
{
Serial.print("\n"); Serial.print("\n");
if (person_a > person_b && person_a > person_c && person_a > person_d)
{
Serial.print("Person A won with ");
Serial.print(person_a);
Serial.print(" votes");
lcd.clear();
lcd.print("Person A won");
lcd.setCursor(0, 1);
lcd.print("with "); lcd.print(person_a); lcd.print(" votes");
}
else if (person_b > person_a && person_b > person_c && person_b > person_d)
{
Serial.print("Person B won with ");
Serial.print(person_b);
Serial.print(" votes");
lcd.clear();
lcd.print("Person B won");
lcd.setCursor(0, 1);
lcd.print("with "); lcd.print(person_b); lcd.print(" votes");
}
else if (person_c > person_a && person_c > person_b && person_c > person_d)
{
Serial.print("Person C won with ");
Serial.print(person_c);
Serial.print(" votes");
lcd.clear();
lcd.print("Person C won");
lcd.setCursor(0, 1);
lcd.print("with "); lcd.print(person_c); lcd.print(" votes");
}
else if (person_d > person_a && person_d > person_b && person_d > person_c)
{
Serial.print("Person D won with ");
Serial.print(person_d);
Serial.print(" votes");
lcd.clear();
lcd.print("Person D won");
lcd.setCursor(0, 1);
lcd.print("with "); lcd.print(person_d); lcd.print(" votes");
}
}
JS code:-
var Graph = new boltGraph();
Graph.setChartType("lineGraph");
Graph.setAxisName('X-Axis Name','Y-axis Name');
Graph.plotChart('time_stamp','person_a', 'person_b', 'person_c', 'person_d');
The values for variables finally were 7,3,2,3
but only 2nd and 3rd are being plotted.
I am attaching some relevant screenshots
I have spent hours thinking and tinkering and now I really would appreciate some help.