37 lines
960 B
Arduino
37 lines
960 B
Arduino
|
|
||
|
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:
|
||
|
|
||
|
}
|