Arduino Sketch MakerPlot Setpoint Example With GUI Control
// MakerPlot Arduino Setpoint with GUI Control
// This sketch is in the public domain
const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
const int LEDpin = 9; // Analog output pin that the LED is attached to
const int SW1pin = 2; // Pushbutton switch, raise setpoint
const int SW2pin = 3; // Pushbutton switch, lower setpoint
int sensorValue = 0; // value read from the pot
int setPoint = 100; // Initial value of setPoint
int SW1state = 0; // Store state of SW1
int SW2state = 0; // Store state of SW2
int LEDstate = 0; // Store state of LED
void setup() {
// configure hardware
pinMode(SW1pin, INPUT_PULLUP); // Enable pull-ups on switches
pinMode(SW2pin, INPUT_PULLUP);
pinMode(LEDpin, OUTPUT); // set LED to be an output pin
// initialize serial communications at 9600 bps:
Serial.begin(9600);
delay(2000); // allow comms to stabilize
Serial.println(); // send a CR in case data in queue
Serial.println("!RSET"); // send instruction to reset plot
Serial.println("!SPAN 0,1000"); // set Y axis span from 0 to 1000
Serial.println("!TMAX 180"); // set time axis to 180 seconds
Serial.println("!PLOT ON"); // Enable plotting
Serial.println("(@TEXT 35A,105A,1.5,(RED),My Arduino Interface");
}
void loop() {
// read the analog in value
sensorValue = analogRead(analogInPin);
// Check pot value against setpoint, if above light LED
if (sensorValue > setPoint)
{
LEDstate = 1;
Serial.println("!BELL"); // sound PC Bell
delay(500);
}
else
LEDstate = 0;
digitalWrite(LEDpin,LEDstate);
// Check states of pushbuttons, if pressed change setpoint up or down
SW1state = digitalRead(SW1pin);
if (SW1state == 0)
setPoint++;
SW2state = digitalRead(SW2pin);
if (SW2state == 0)
setPoint--;
// print the analog values formatted for MakerPlot
Serial.print(sensorValue); // send 1st value
Serial.print(","); // send comma delimiter
Serial.println(setPoint); // send 2nd value with carriage return
// print the digital values formatted for MakerPlot
Serial.print("%"); // send binary indicator
Serial.print(SW1state); // send 1/0 for SW1
Serial.print(SW2state); // send 1/0 for SW2
Serial.println(LEDstate); // send 1/0 for LED with carriage return
// wait 100 milliseconds before the next loop
delay(100);
}
// This sketch is in the public domain
const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
const int LEDpin = 9; // Analog output pin that the LED is attached to
const int SW1pin = 2; // Pushbutton switch, raise setpoint
const int SW2pin = 3; // Pushbutton switch, lower setpoint
int sensorValue = 0; // value read from the pot
int setPoint = 100; // Initial value of setPoint
int SW1state = 0; // Store state of SW1
int SW2state = 0; // Store state of SW2
int LEDstate = 0; // Store state of LED
void setup() {
// configure hardware
pinMode(SW1pin, INPUT_PULLUP); // Enable pull-ups on switches
pinMode(SW2pin, INPUT_PULLUP);
pinMode(LEDpin, OUTPUT); // set LED to be an output pin
// initialize serial communications at 9600 bps:
Serial.begin(9600);
delay(2000); // allow comms to stabilize
Serial.println(); // send a CR in case data in queue
Serial.println("!RSET"); // send instruction to reset plot
Serial.println("!SPAN 0,1000"); // set Y axis span from 0 to 1000
Serial.println("!TMAX 180"); // set time axis to 180 seconds
Serial.println("!PLOT ON"); // Enable plotting
Serial.println("(@TEXT 35A,105A,1.5,(RED),My Arduino Interface");
}
void loop() {
// read the analog in value
sensorValue = analogRead(analogInPin);
// Check pot value against setpoint, if above light LED
if (sensorValue > setPoint)
{
LEDstate = 1;
Serial.println("!BELL"); // sound PC Bell
delay(500);
}
else
LEDstate = 0;
digitalWrite(LEDpin,LEDstate);
// Check states of pushbuttons, if pressed change setpoint up or down
SW1state = digitalRead(SW1pin);
if (SW1state == 0)
setPoint++;
SW2state = digitalRead(SW2pin);
if (SW2state == 0)
setPoint--;
// print the analog values formatted for MakerPlot
Serial.print(sensorValue); // send 1st value
Serial.print(","); // send comma delimiter
Serial.println(setPoint); // send 2nd value with carriage return
// print the digital values formatted for MakerPlot
Serial.print("%"); // send binary indicator
Serial.print(SW1state); // send 1/0 for SW1
Serial.print(SW2state); // send 1/0 for SW2
Serial.println(LEDstate); // send 1/0 for LED with carriage return
// wait 100 milliseconds before the next loop
delay(100);
}