/* This code is a basic sketch to communicate with Processing through Serial. It is a blueprint in which you can put your own code specified for your own buttons, potentiometers or sensors. It has a handshake to make sure we have contact and the format in which we are communicating is decided It is important to construct the message this same way, so that Processing knows how to deconstruct it and send correct OSC-messages to our DAW made for werkcollege AV&IT oct 2017 */ // baud rate const long baudRate = 9600; // time to wait in ms between polls to the pins const int loopPauseTime = 200; // milli seconds // start and end values for the message sent on Serial const String startString = "*", endString = "#"; const char contactCharacter = '|'; const int analogInPin = A2; const int analogInPin2 = A0; //int sensorpin = A5; int sensorValue1 = 0; int outputValue1 = 0; int sensorValue2 = 0; int outputValue2 = 0; const int playPin = 2; // play const int previousPin = 4; //precvious song const int nextPin = 6; //next song const int pauzePin = 8; //pauze void establishContact() { while (Serial.available() <= 0) { Serial.print(contactCharacter); // send a char and wait for a response... delay(100); } Serial.read(); Serial.begin(9600); } void setup() { pinMode(playPin, INPUT); pinMode(previousPin, INPUT); pinMode(nextPin, INPUT); pinMode(pauzePin, INPUT); pinMode(analogInPin, INPUT); pinMode(analogInPin2, INPUT); Serial.begin(9600); while (!Serial); // wait for handshake establishContact(); } void loop() { // STEP 1: READ BUTTONS int knop1 = digitalRead(playPin); int knop2 = digitalRead(previousPin); int knop3 = digitalRead(nextPin); int knop4 = digitalRead(pauzePin); sensorValue1 = analogRead(analogInPin); float v1 = map(sensorValue1, 0, 1023, -9000, 25000); sensorValue2 = analogRead(analogInPin); float v2 = map(sensorValue2, 0, 10000, 0, 10); //sensorValue2 = analogRead(sensorpin); //outputValue2 = map(sensorValue2, 0, 700, 0 ,100); // examples: // float v0 = map(bpm, 0, 1023, 60, 250); // if you want to use a normalized float (eg. for volume) // float v1 = map(analogRead(pin2), fromMin, fromMax, 0, 100) / 100.0; // STEP 2: WRITE MESSAGE // write start of message Serial.print(startString); // start a message sequence // write all the name,value pairs, separated by commas Serial.print("knop 1"); Serial.print(","); Serial.print(knop1); Serial.print(","); Serial.print("knop 2"); Serial.print(","); Serial.print(knop2); Serial.print(","); Serial.print("knop 3"); Serial.print(","); Serial.print(knop3); Serial.print(","); Serial.print("knop 4"); Serial.print(","); Serial.print(knop4); Serial.print(","); Serial.print("n/master/volume"); Serial.print(","); Serial.print(v1); Serial.print(","); Serial.print("fx"); Serial.print(","); Serial.print(v2); Serial.print(","); /* Serial.print("s/beat/str"); Serial.print(","); Serial.print(outputValue2); //Serial.print(","); // write the end of message*/ Serial.print(endString); // wait for a while.. delay(100); }