It is my first project but I’ve spent weeks trying to figure this out before posting.
Here’s my sketch:
#include <HologramSIMCOM.h>
#define RX_PIN 2 //SIMCom RX - MCU TX
#define TX_PIN 3 //SIMCom TX - MCU RX
#define RESET_PIN 4 //SIMCom reset
#define HOLO_KEY "hidden<" //replace w/your SIM key
#define CONNECT_LED 12
#define VOTE1_BTN_PIN 6
#define VOTE1_LED_PIN 7
#define VOTE2_BTN_PIN 9
#define VOTE2_LED_PIN 10
HologramSIMCOM Hologram(TX_PIN, RX_PIN, RESET_PIN, HOLO_KEY); // Instantiate Hologram
String VOTE1_VALUE = "chicago";
String VOTE2_VALUE = "newYork";
String HOLOGRAM_TOPIC = "vote";
void setup() {
Serial.begin(9600);
while(!Serial);
// Start modem and connect to Hologram's global network
Hologram.debug();
//set modes for used pins
pinMode(CONNECT_LED, OUTPUT);
pinMode(VOTE1_BTN_PIN, INPUT);
pinMode(VOTE1_LED_PIN, OUTPUT);
pinMode(VOTE2_BTN_PIN, INPUT);
pinMode(VOTE2_LED_PIN, OUTPUT);
bool cellConnected = Hologram.begin(9600, 8888); // set baud to 19200 and start server on port 8888
if(cellConnected) {
digitalWrite(CONNECT_LED, HIGH);
}
}
void loop() {
Hologram.debug();
if(digitalRead(VOTE1_BTN_PIN) == HIGH) {
sendVote(VOTE1_VALUE,VOTE1_LED_PIN);
}
if(digitalRead(VOTE2_BTN_PIN) == HIGH) {
sendVote(VOTE2_VALUE,VOTE2_LED_PIN);
}
}
void sendVote(String VOTE_VALUE, const int VOTE_LED) {
digitalWrite(VOTE_LED, HIGH);
// send to the Hologram Data Router
if(Hologram.send(VOTE_VALUE, HOLOGRAM_TOPIC)) {
// blink LED if vote was successful
// this is crappy code, consider refactoring
digitalWrite(VOTE_LED, LOW);
delay(100);
digitalWrite(VOTE_LED, HIGH);
delay(100);
digitalWrite(VOTE_LED, LOW);
delay(100);
digitalWrite(VOTE_LED, HIGH);
delay(100);
digitalWrite(VOTE_LED, LOW);
} else {
digitalWrite(VOTE_LED, LOW);
}
}
Thanks for all ideas.