Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //please note that this is a work-in-progress sketch and probably doesn't work
- #define padCount 2
- //number of pads
- elapsedMicros padTimer1; //seems to be accurate from >1000
- elapsedMicros padTimer2;
- int padTime1 = 1000; //the pad will be checked every 1000us
- int padAttack = 10;
- int padTicks = 600;
- int padValue[padCount];
- int ticks=0;
- int oldValue[padCount];
- boolean triggered[padCount] ;
- #define led 13
- void setup(){
- Serial.begin(9600);
- pinMode(12,INPUT_PULLUP);
- pinMode(led, OUTPUT);
- digitalWrite(led, HIGH);
- analogReference(INTERNAL);
- analogReadAveraging(16); //32 is max
- analogReadRes(7);
- padTimer1 = 0;
- padTimer2 = 0;
- Serial.println(padTimer1);
- }
- void loop() {
- while (digitalRead(12) == HIGH){
- if (padTimer1 >= padTime1) { //check the sensor at a specified time
- Serial.println("first:"+padTimer1);
- padTimer1 =- padTime1; //reset the timer
- Serial.println(padTimer1);
- for (int i = 0; i<padCount;i++){
- padValue[i] = analogRead(i+14); //read and save all values
- }
- for (int i = 0; i<padCount;i++){
- Serial.print(i+" sensor is ");
- Serial.println( padValue[i] );
- if ( padTimer2 >= padTicks * padTime1){
- if (triggered[i] == HIGH){
- Serial.println(" Trigger off");
- //usbMIDI.sendNoteOff(60, 0, 1);
- digitalWrite(led, HIGH);
- triggered[i] = LOW;
- }
- if (padValue[i] >= padAttack){
- if (oldValue[i] >= padValue[i]){
- triggered[i] = HIGH;
- Serial.print(i+" "+ padValue[i] );
- Serial.println(" BAM");
- //usbMIDI.sendNoteOn(60, padValue, 1);
- //tone (0, map(padValue,0,1023,220,1000),100);
- digitalWrite(led, LOW);
- padTimer2 = 0;
- oldValue[i] = 0;
- }
- else if (oldValue[i] < padValue[i]){
- oldValue[i] = padValue[i];
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement