Commit e00a8c10 authored by Evan Raskob's avatar Evan Raskob

some bug fixed, copyright additions, and further instructions after 1st lesson

parent 81c66e85
......@@ -51,7 +51,6 @@ void setupGUI() {
;
//Serial Port selector
// serialddl = cp5.addDropdownList("SerialPort")
serialddl = cp5.addScrollableList("SerialPort")
.setPosition(50, 100)
.setSize(200, 200)
......
......@@ -6,11 +6,16 @@ import processing.serial.*;
/*
* This example reads sensor data from an Arduino
* and relays it to another program using OSC.
* Try changing the TEST_ON and TEST_OFF functions to send some serial data to an Arduino (or other microcontroller) and
* test how that works. Then, in the Serial_functions tab, edit the serialEvent() function to handle some
* incoming serial messages from the Arduino.
*
* by Evan Raskob (e.raskob@gold.ac.uk)
* copyright 2019 Evan Raskob (e.raskob@gold.ac.uk)
* Jan. 29, 2019
* MIT Licensed. Use at your own risk.
*/
// whether we're connected to an Arduino or not:
boolean applicationRunning = false;
//start everything
......@@ -51,7 +56,13 @@ public void TEST_ON()
{
if (applicationRunning)
{
// Whatever is in here gets run when the TEST_ON button is pressed.
// the following works with the SerialSendReceiveTest sketch for Arduino to turn the LEDs on and off
serial.write("ledon" + stopChar);
// this one works with the SerialParseTest Arduino sketch:
// serial.write("n 1,0,0" + stopChar);
}
println("finished");
}
......@@ -60,6 +71,10 @@ public void TEST_OFF()
{
if (applicationRunning)
{
// Whatever is in here gets run when the TEST_OFF button is pressed.
// the following works with the SerialSendReceiveTest sketch for Arduino to turn the LEDs on and off
serial.write("ledoff" + stopChar);
}
println("finished");
......@@ -73,7 +88,6 @@ public void ERROR()
serial.write("bad data" + stopChar);
// could also leave out the stopChar and see what happens!
}
}
/************************************************************************************
......
......@@ -32,6 +32,9 @@ void serialEvent(Serial serial) {
String[] msgs = split(input, ',');
// "c,2,3,4" --> ["c", "2", "3", "4"]
// TODO: handle message here!
}
......
......@@ -11,7 +11,7 @@ int z;
void setup() {
// this is the string we're reading from. It's a few values separated by commas
const char buf[] = "N 90,80,180";
const char buf[] = "N 1,2,3";
// sscanf reads the values and stores them in variables we just declared. %d represents a number of digits to read
int n = sscanf(buf, "%c %d,%d,%d", &c, &x, &y, &z);
......@@ -72,8 +72,18 @@ void loop() {
// now handle bytes read
// NXXX means note
// sscanf reads the values and stores them in variables we just declared. %d represents a number of digits to read
// the "n" returned by this function is the number of matches. Whitespace is ignored, by default.
int n = sscanf(buffer, "%c %d,%d,%d", &c, &x, &y, &z);
//-----------------------------------------------------------------------------------------------
// PUT YOUR CODE HERE! Make it do something, like turn on a NEOPixel array to a colour (r,g,b).
// do something like:
// if (c == 'l') {
// pinMode(LED_BUILTIN, OUTPUT);
// digitalWrite(LED_BUILTIN, x);
// }
Serial.print(c);
Serial.print(' ');
Serial.print(x);
......
......@@ -5,6 +5,8 @@
* Maybe you just want to turn somethings on and off? Or control a motor speed?
*
* Then, what data do you want from it? And how often?
* copyright Evan Raskob (e.raskob@gold.ac.uk) Jan. 29, 2019
* MIT Licensed.
*/
const char stopChar = '\n'; //new line character
......@@ -15,7 +17,6 @@ const long timeoutMs = 400; // timeout if message took too long
const char LEDONCommand[] = "ledon";
const char LEDOFFCommand[] = "ledoff";
long bytesReceived = 1;
/**
* Blink an LED
......@@ -102,8 +103,6 @@ void loop()
// stop if we've taken too much time!
if (millis() - startTime > timeoutMs)
{
bytesToRead = 0;
// flash error lights
for (int i = 0; i < 4; i++)
{
......@@ -143,7 +142,7 @@ void loop()
Serial.println(':');
// now handle bytes read
handleMessage(messageReceived);
handleMessage(buffer);
charsRead = 0; // go back to beginning of buffer for next command
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment