Advertisement
Guest User

Untitled

a guest
Apr 29th, 2013
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.03 KB | None | 0 0
  1. //please note that this is a work-in-progress sketch and probably doesn't work
  2.  
  3. #define padCount 2
  4. //number of pads
  5.  
  6. elapsedMicros padTimer1; //seems to be accurate from >1000
  7. elapsedMicros padTimer2;
  8.  
  9. int padTime1 = 1000; //the pad will be checked every 1000us
  10.  
  11.  
  12. int padAttack = 10;
  13. int padTicks = 600;
  14.  
  15. int padValue[padCount];
  16. int ticks=0;
  17. int oldValue[padCount];
  18. boolean triggered[padCount] ;
  19.  
  20. #define led 13
  21.  
  22. void setup(){
  23.   Serial.begin(9600);
  24.   pinMode(12,INPUT_PULLUP);
  25.   pinMode(led, OUTPUT);
  26.   digitalWrite(led, HIGH);
  27.   analogReference(INTERNAL);
  28.   analogReadAveraging(16); //32 is max
  29.   analogReadRes(7);
  30.  
  31.   padTimer1 = 0;
  32.   padTimer2 = 0;
  33.   Serial.println(padTimer1);
  34. }
  35.  
  36. void loop() {
  37.   while (digitalRead(12) == HIGH){
  38.     if (padTimer1 >= padTime1) { //check the sensor at a specified time
  39.  
  40.       Serial.println("first:"+padTimer1);
  41.       padTimer1 =- padTime1; //reset the timer
  42.       Serial.println(padTimer1);
  43.  
  44.       for (int i = 0; i<padCount;i++){
  45.         padValue[i] = analogRead(i+14); //read and save all values
  46.       }
  47.  
  48.       for (int i = 0; i<padCount;i++){
  49.         Serial.print(i+" sensor is  ");
  50.         Serial.println( padValue[i] );
  51.         if ( padTimer2 >= padTicks * padTime1){
  52.  
  53.           if (triggered[i] == HIGH){
  54.             Serial.println(" Trigger off");
  55.             //usbMIDI.sendNoteOff(60, 0, 1);
  56.             digitalWrite(led, HIGH);
  57.             triggered[i] = LOW;
  58.           }
  59.  
  60.           if (padValue[i] >= padAttack){
  61.             if (oldValue[i] >= padValue[i]){
  62.               triggered[i] = HIGH;
  63.               Serial.print(i+" "+ padValue[i] );
  64.               Serial.println(" BAM");
  65.               //usbMIDI.sendNoteOn(60, padValue, 1);
  66.               //tone (0, map(padValue,0,1023,220,1000),100);
  67.               digitalWrite(led, LOW);
  68.               padTimer2 = 0;
  69.               oldValue[i] = 0;
  70.             }
  71.             else if (oldValue[i] < padValue[i]){
  72.               oldValue[i] = padValue[i];
  73.             }
  74.           }
  75.         }
  76.  
  77.       }
  78.  
  79.     }
  80.   }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement