Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define w1 1
- #define w2 1
- #define w3 1
- #define w4 1
- void noteOn(byte channel, byte note, byte velocity)
- {
- midiMsg(channel+0x90, note, velocity);
- }
- void midiMsg(byte cmd, byte data1, byte data2)
- {Serial.write(cmd);
- Serial.write(data1);
- Serial.write(data2);
- }
- int count = 1;
- unsigned long old_time = millis();
- unsigned long new_time, dt, old_dt=100;
- unsigned long period = 1000;
- unsigned long t[4], dtAvg;
- long sensorValue, prev_sensorValue = analogRead(A2), diff[4], diffval;
- void acdc(int dt){
- noteOn(9, 44, 127);
- if(count==1)
- noteOn(9, 36, 127);
- if(count==3)
- noteOn(9, 38, 127);
- count++;
- delay(dt);
- if(count>4)
- count = 1;
- }
- void setup() {
- Serial.begin(9600);
- }
- void loop() {
- int thresh = analogRead(A0);
- delay(1);
- prev_sensorValue = sensorValue;
- //Serial.println(prev_sensorValue);
- sensorValue = analogRead(A2);
- //Serial.print(sensorValue);
- //Serial.print(' ');
- diff[0] = diff[1];
- diff[1] = diff[2];
- diff[2] = diff[3];
- diff[3] = diffval;
- dtAvg = (w1*diff[0] + w2*diff[1] + w3*diff[2] + w4*diff[3])/(w1+w2+w3+w4);
- if(sensorValue < 500){
- //Serial.println(diff);
- //Serial.println(sensorValue);
- new_time = millis();
- dt = new_time-old_time;
- if(dt>50 && dt<1000);
- old_time = new_time;
- }
- delay(1);
- if(dt>50 && dt<500){
- acdc(dt);
- }
- //OLD
- //noteOn(9, 40, 120);
- //Serial.println(dt);
- //delay(dt);
- //old_dt = dt;
- //else{
- //noteOn(9, 49, 120);
- //delay(old_dt);
- //}
- /*t[0] = t[1];
- t[1] = t[2];
- t[2] = t[3];
- t[3] = dt;
- dtAvg = (w1*t[0] + w2*t[1] + w3*t[2] + w4*t[3])/(w1+w2+w3+w4);
- if (dtAvg >50 && dtAvg < 600){ */
- //acdc(dtAvg);
- //}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement