Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Arduino / Bluefruit to OpenFrameworks
int lightPin = 0; //define a pin for Photo resistor
int light; // variable that holds input value from sensor.
//This will be mapped from 0 - 255 so it can be send as a Byte for OF to recieve
int bytesToSend[2]; //Array that hold the values you will be sending to OF
void setup()
Serial.begin(9600); //Begin serial communcation
Serial.print("a"); // Initializes serial by sending an "a" that OF reads so it opens its serial communication
void loop()
light = analogRead(lightPin); // assigning sensor value to value variable
bytesToSend[0] = map(light, 0,800,0,255); // mapping so information can be sent as Byte
//& declaring that the first value in the array is going to be the sensor value "light"
bytesToSend[1] = 0; // This is just to show that you can send multiple inputs
if (Serial.available() > 0) { // IF OF sends flag i.e. "a" run the for Loop
for(int i = 0; i < 2 ; i++){ // loops through the Bytes Array
Serial.write(bytesToSend[i]); // When using Serial Write you are sending the Info as a Byte which is needed to send info to OF
// This means this info won't appear in your arduino serial viewer
//Serial.print(bytesToSend[i]); //Use print to view your values in the Arduino serial Port
//Serial1 is used when using the Micro Arduino
Serial.print("\r\n"); //Not sure if neccessary for OF but makes your Ardunio Serial port scroll so you know it is sending the Info
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment