Advertisement
Guest User

Untitled

a guest
Jan 19th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include < avr/interrupt.h >
  2. #include "LedControl.h"
  3. LedControl lc=LedControl(12,11,10,1);
  4. int rotaryInterrupt = 2; //pin to trigger rotary encoder check
  5. int rotaryCheck = 1; //pin which is checked
  6. int clockIn = 3; //pin for external clock
  7. bool rotencodAxis = '0'; //sets axis to use in currentLocation, 0 is x, 1 is y
  8. int channels [] = [4,5,6,7]; //4 outputs used
  9. bool editMode = true; //enables editing pins
  10. int step = 0; //current step to output
  11. int ledState = LOW; //blink base state
  12. unsigned lomg milliseconds = 0; //millisecond counter
  13. int spdtHigh = 8; //pin for setting a drum step to play
  14. int spdtLow = 9; //pin for setting a drum step to not do that
  15. int rotencodButton = 10; //rotary encoder button used to set axis
  16. int editButton = 11; //button used to toggle edit mode
  17. int currentLocation [] = [0, 0]; //where the blinking and drum toggling will occur
  18. bool pinMatrix[4][8] = {
  19.  
  20.   {false,  false,  false, false,  false,  false, false },
  21.  
  22.   {false,  false,  false, false,  false,  false, false },
  23.  
  24.   {false,  false,  false, false,  false,  false, false },
  25.  
  26.   {false,  false,  false, false,  false,  false, false }
  27.  ///used to keep the drum loop
  28.  
  29.  
  30. };
  31. void setup() {
  32. pinMode(clockIn, INPUT_PULLUP); //set to pullup to check if the signal rises
  33. pinMode(rotaryInterrupt, INPUT_PULLUP); //set to pullup to check if the signal rises
  34. pinMode(rotaryCheck, INPUT);
  35. pinMode(rotencodButton, INPUT);
  36. pinMode(editButton, INPUT);
  37. pinMode(spdtHigh, INPUT);
  38. pinMode(spdtLow, INPUT);
  39. attachInterrupt(digitalPinToInterrupt(clockIn), clockIterate, RISING); //sets the clock moving the pattern ahead one
  40. attachInterrupt(digitalPinToInterrupt(rotaryInterrupt), rotaryEvaluate, RISING); //interprets the movement of the rotary encoder
  41.   for (int thisPin = 0; thisPin < pinCount; thisPin++) {
  42.     pinMode(channels[thisPin], OUTPUT);
  43.   } //sets each channel to an output
  44. lc.shutdown(0,false); //idk what it does but it makes led driver work
  45. lc.setIntensity(0,8); //how bright the leds will be
  46. }
  47.  
  48. void loop() {
  49. if (editButton == HIGH);{
  50.   editMode = !editMode;
  51. } //toggles the edit mode when button is hit
  52. if (rotencodButton == HIGH);{
  53.   RotencodAxis = !rotencodAxis;
  54. } //same, but for the axis the rotary encocder controls
  55.  
  56.         for(int k = 0; k < 8; i++){
  57.                if (k = step;){
  58.                lc.setLed(0,step,0,true);
  59.                }
  60.                else {
  61.                 lc.setLed(0,k, false);
  62.                } //sets the light to be high or in the matrix based on whether it's the active step in the sequence
  63.         }
  64.   for(int j = 0; j <4 ; i++){
  65.     if (pinMatrix [j][k] = true){
  66.     lc.setLed(0,j,k,true);
  67.  
  68.   }
  69.   else {
  70.       lc.setLed(0,j,k,false);
  71.   }
  72.   }//sets each light based on its value in pinmatrix
  73.  
  74. if (editmode = true) {
  75.    unsigned long currentMillis = millis();
  76.  
  77.   if (currentMillis - previousMillis >= interval) {
  78.     previousMillis = currentMillis;
  79.  
  80.     if (ledState == LOW) {
  81.       ledState = HIGH;
  82.     } else {
  83.       ledState = LOW;)
  84.     }
  85.   }
  86. lc.setled(0, currentLocation[0], currentLocation[1], ledState);
  87.  if (spdtHigh = HIGH) {
  88.    pinmatrix[currentLocation] = HIGH;
  89.  }
  90.   if (spdtLow = HIGH) {
  91.    pinmatrix[currentLocation] = LOW;
  92.  }  
  93. }//if edit mode is on, blink the led that corresponds to the step to be edited
  94. }
  95.  
  96. void clockIterate (){
  97.   if (step == 7){
  98.     step = 0;
  99.   }
  100.   else{
  101.     for(int i=0; i<4; i++){
  102.     digitalWrite(channel[i],channel[i][step]);
  103.     step = step + 1;
  104.   }
  105. }
  106. }//if there's a clock pulse, move the sequence forward once
  107. void rotaryEvaluate () {
  108.   if (editmode == true) {
  109.   if (rotaryCheck == HIGH) {
  110.      currentLocation[rotencodAxis]= currentLocation[rotencodAxis] + 1;
  111.   }
  112.   else {
  113.     currentLocation[rotencodAxis]= currentLocation[rotencodAxis] - 1;
  114.   }
  115. }
  116. }//checks whether the rotary encoder was moved and sets the position accordingly
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement