Lab_interaccio/2013/Oval/piezo_input_midi/piezo_input_midi.ino

37 lines
960 B
Arduino
Raw Permalink Normal View History

2025-02-25 21:29:42 +01:00
int sensorPin = A0; // select the input pin for the potentiometer
int ledPin = 2; // select the pin for the LED
float sensorValue = 0; // variable to store the value coming from the sensor
MIDIEvent e1 = {0x09, 0x90, 60, 64};
MIDIEvent e2 = {0x08, 0x80, 60, 0};
void setup() {
// declare the ledPin as an OUTPUT:
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
//Serial.begin(9600);
}
void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
// turn the ledPin on
if(sensorValue>50)
{
delayMicroseconds(2000);
//sensorValue = analogRead(sensorPin)*(4850/1023.);
sensorValue = analogRead(sensorPin)/8;
MIDIEvent e1 = {0x09, 0x90, 60, sensorValue};
MIDIUSB.write(e1);
//Serial.println(sensorValue);
delay(50);
MIDIUSB.write(e2);
digitalWrite(ledPin, HIGH);
digitalWrite(ledPin, LOW);
}
// stop the program for <sensorValue> milliseconds:
}