• arduino i2c guitar effects control

    kevinl7778        
    0 Likes0 Commentsc_cpp

    ////////////////////////////////////////////////////////Include default libraries
    #include <Wire.h>
    
    ////////////////////////////////////////////////////////Set up constants
    
    int comm1 = 4; 
    int comm2 = 5; 
    int DelayTime = 250;
    int FS[]{13,12,11,10,9,8,7,6,5};
    int Knb[18];
    int led[]{4,3,2,A2,A3};
    int Group = 1;
    int GroupLastState = 0;
    int Knob = 0;
    
    int comm = comm1;
    
    ////////////////////////////////////////////////////////Start ini proccess
    
    
    void setup(){
        init1(); //Set pinmode for foot switches and leds
      	ledSet(); //Sweep through leds and set 0 on
     	Wire.begin();
      	Serial.begin(9600);}
    
    ////////////////////////////////////////////////////////////Set var's :Need to change to 0-17 all set to 0
    
    int x = 0;
    int y = 0;
    
    
    ////////////////////////////////////////////////////////////Main loop
    
    void loop()
    {
      Wire.beginTransmission(comm);
      //for (int i = 0; i <= 8; i++)
      //{digitalRead(FS[i]); if (digitalRead(FS[i]) == LOW)
      //{Serial.println(String("x = ")+ x);Serial.println(String("Bingo ") +FS[i]);};}
      Grouping();
      Switch(); 
      Knobs();  
      x=digitalRead(FS[0]);
      Wire.write(x);
      
      Wire.endTransmission(comm); 
      delay(100);
     // Wire.beginTransmission(comm); 
      //y=digitalRead(FS[1]);
      //Wire.write(y);
      //Serial.println(String("y = ")+ y);  
      //Wire.endTransmission(comm);
      delay(100);
    
    }
    
    
    //////////////////////////////////////////////////////////Init buttons and outputs
    
    
    void init1(){
      for (int i=0; i<9; i++){pinMode(FS[i], INPUT_PULLUP);}
      for (int j=0; j<5; j++){pinMode(led[j],OUTPUT);}}
      
    
    //////////////////////////////////////////////////////////////////////////////////////////////////////////Init Knight Rider lights
    
    
    
    void ledSet(){ 
      for (int j = 0; j <= 4; j++) {digitalWrite(led[j], HIGH); delay(DelayTime);digitalWrite(led[j], LOW);Serial.println(String("J++") +j);}
      for (int j = 4; j >= 0; j--) {digitalWrite(led[j], HIGH); delay(DelayTime);digitalWrite(led[j], LOW);Serial.println(String("J--") +j);}
      digitalWrite(led[0], HIGH);}
    
    
    
    //////////////////////////////////////////////////////////////////////////////////////////////////////Changing Comunication group
    
    
    void Switch(){ 
      if (Group != GroupLastState){
      switch (Group) {
      case 1:
        comm = comm1;
        digitalWrite(led[1], HIGH);
        Serial.println(String("Group = ") +Group);
        Serial.println(String("comm = ") +comm);
        GroupLastState =1;
        break;
      case 2:
        comm = comm1;
        digitalWrite(led[2], HIGH);
        Serial.println(String("Group = ") +Group);
        Serial.println(String("comm = ") +comm);
        GroupLastState =2;
        break;
      case 3:
        comm = comm2;
        digitalWrite(led[3], HIGH);
        Serial.println(String("Group = ") +Group);
        Serial.println(String("comm = ") +comm);
        GroupLastState =3;
        break;
      case 4:
        comm = comm2;
        digitalWrite(led[4], HIGH);
        Serial.println(String("Group = ") +Group);
        Serial.println(String("comm = ") +comm);
        GroupLastState =4;
        break;}}}
    
    
    
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////Switching groups
    
    
    void Grouping(){if  (digitalRead(FS[1]) == LOW && digitalRead(FS[0]) == LOW) {Group += 1;if (Group > 4) {Group = 1;}for (int i=1; i<5; i++){digitalWrite(led[i], LOW);};}
                   
                   if  (digitalRead(FS[8]) == LOW && digitalRead(FS[7]) == LOW) {Group -= 1;if (Group < 1) {Group = 4;}for (int i=1; i<5; i++){digitalWrite(led[i], LOW);};}
                   }
    
    
    
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////Turning Knobs
    void Knobs(){if  (digitalRead(FS[0,3,6]) == LOW){Knob += 1; Serial.println(String("Knob = ") +Knob);}
                   else {Knob = 0;}
     }
    

Comments (0)