Skip to content

Instantly share code, notes, and snippets.

@jgiovanni
Created September 27, 2017 18:26
Show Gist options
  • Save jgiovanni/6b80888629e3cec811a2fc7fab7e9217 to your computer and use it in GitHub Desktop.
Save jgiovanni/6b80888629e3cec811a2fc7fab7e9217 to your computer and use it in GitHub Desktop.
/*
* Course: Ateliyer 1: Discovery - DGIF-2004
* Prototype: TetherPad
* Group Members: Johan Seaton, Sanmeet Chahil, Jerez Bain
*
* This code is used to allow the arduino to communicat with Ableton Live using the downloadable Connection Kit and Max for Live
*/
#include <Firmata.h>
byte analogPin = 0;
void analogWriteCallback(byte pin, int value)
{
// Because PMW pins can be used to replicate analog behavior, check if the pin used is PMW
if (IS_PIN_PWM(pin)) {
pinMode(PIN_TO_DIGITAL(pin), OUTPUT);
analogWrite(PIN_TO_PWM(pin), value);
}
}
void setup()
{
// Setup Firmata Firmware
Firmata.setFirmwareVersion(FIRMATA_FIRMWARE_MAJOR_VERSION, FIRMATA_FIRMWARE_MINOR_VERSION);
// Attach event callback 'analogWriteCallback', to changes in 'ANALOG_MESSAGE'
Firmata.attach(ANALOG_MESSAGE, analogWriteCallback);
// Similar to Serial.begin, except for Firmata
Firmata.begin(57600);
}
void loop()
{
// Continue to process inputs while firmata is available
while (Firmata.available()) {
Firmata.processInput();
}
// do one analogRead per loop, so if PC/Mac is sending a lot of
// analog write messages, we will only delay 1 analogRead
Firmata.sendAnalog(analogPin, analogRead(analogPin));
analogPin = analogPin + 1;
// in each loop the analogPin value increments, sending values one at a time.
// if the value exceeds the total number of available pins, start at 0 again
if (analogPin >= TOTAL_ANALOG_PINS) analogPin = 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment