Member #764075

Member Since: January 18, 2016

Country: United States

  • Can anyone see why this code works on UNO but not on MEGA?? its only partially finished, in testing i cannot make it work on MEGA. it will be used with processing to operate 5v relays. with relays hooked up it wont work with either.

    int Pin[] = {22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42}; //Array of pins to controll lights int value = 0; // variable to keep the actual value

    void setup() { //Initialize pins as OUTPUTS and begin serial connection for(int i=22; i<42 ; i++){ pinMode(Pin[i], OUTPUT); pinMode(Pin[13], OUTPUT); } Serial.begin(9600);

    }

    void loop() {

    //if (Serial.available()){ int input = Serial.read(); // read serial

    switch (input){ case 22: //If processing passes a '22' do case one

      if(input == 22){
    
        digitalWrite(Pin[13],HIGH);
        delay(3000);
        digitalWrite(Pin[13],LOW);
    
       }
       break;
    case 23:
      if(input == 23){  //If Processing passes a '23' do case two
      digitalWrite(Pin[13],HIGH);
        delay(3000);
        digitalWrite(Pin[13],LOW);
    
       }
       break;
    case 24:
      if(input == 24){  //If Processing passes a '24' do case three
      digitalWrite(Pin[24],HIGH);
        delay(3000);
        digitalWrite(Pin[24],LOW);
    
       }
       break;
    case 25:
      if(input == 25){  //If Processing passes a '25' do case four
      digitalWrite(Pin[25],HIGH);
        delay(3000);
        digitalWrite(Pin[25],LOW);
    
       }
       break;
    case 26:
      if(input == 26){  //If Processing passes a '26' do case five
      digitalWrite(Pin[26],HIGH);
        delay(3000);
        digitalWrite(Pin[26],LOW);
    
       }
       break;
    

    case 27: if(input == 27){ //If Processing passes a '27' do case six digitalWrite(Pin[27],HIGH); delay(3000); digitalWrite(Pin[27],LOW);

       }
       break;
    case 28:
      if(input == 28){  //If Processing passes a '28' do case seven
      digitalWrite(Pin[28],HIGH);
        delay(3000);
        digitalWrite(Pin[28],LOW);
    
       break;
    case 29:
      if(input == 29){  //If Processing passes a '8' do case eight
      digitalWrite(Pin[29],HIGH);
        delay(3000);
        digitalWrite(Pin[29],LOW);
    
       }
       break;
    

    } } }

    processing code

    import g4p_controls.*; import processing.serial.*;

    Serial myPort;

    void setup(){ println(Serial.list()); //String portName = Serial.list()[1]; //change the 0 to a 1 or 2 etc. to match your port myPort = new Serial(this, Serial.list()[1], 9600); myPort.buffer(1);

    size(480, 320, JAVA2D);

    createGUI(); //customGUI();

    }

    void mousePressed() { println("Coordinates: " + mouseX +"," + mouseY); mouseAction(); }

    void mouseAction(){ if( mouseX > 30 && mouseX < 70){ if( mouseY > 10 && mouseY < 60){ println("CH 1"); myPort.write(22); } } if( mouseX > 80 && mouseX < 120){ if( mouseY > 10 && mouseY < 60){ println("CH 2"); myPort.write(23); } } if( mouseX > 130 && mouseX < 170){ if( mouseY > 10 && mouseY < 60){ println("CH 3"); myPort.write(24); } } if( mouseX > 180 && mouseX < 220){ if( mouseY > 10 && mouseY < 60){ println("CH 4"); myPort.write(25); } } if( mouseX > 230 && mouseX < 270){ if( mouseY > 10 && mouseY < 60){ println("CH 5"); myPort.write(26); } } if( mouseX > 280 && mouseX < 320){ if( mouseY > 10 && mouseY < 60){ println("CH 6"); myPort.write(27); } } if( mouseX > 330 && mouseX < 370){ if( mouseY > 10 && mouseY < 60){ println("CH 7"); myPort.write(28); } } if( mouseX > 380 && mouseX < 420){ if( mouseY > 10 && mouseY < 60){ println("CH 8"); myPort.write(29); } } if( mouseX > 40 && mouseX < 110){ if( mouseY > 110 && mouseY < 140){ println("CH 9"); myPort.write(30); } } if( mouseX > 140 && mouseX < 210){ if( mouseY > 110 && mouseY < 140){ println("CH 10"); myPort.write(31); } } if( mouseX > 240 && mouseX < 310){ if( mouseY > 110 && mouseY < 140){ println("CH 11"); myPort.write(32); } } if( mouseX > 340 && mouseX < 410){ if( mouseY > 110 && mouseY < 140){ println("CH 12"); myPort.write(33); } } if( mouseX > 40 && mouseX < 110){ if( mouseY > 160 && mouseY < 190){ println("CH 13"); myPort.write(34); } } if( mouseX > 140 && mouseX < 210){ if( mouseY > 160 && mouseY < 190){ println("CH 14"); myPort.write(35); } } if( mouseX > 240 && mouseX < 310){ if( mouseY > 160 && mouseY < 190){ println("CH 15"); myPort.write(36); } } if( mouseX > 340 && mouseX < 410){ if( mouseY > 160 && mouseY < 190){ println("CH 16"); myPort.write(37); } } }

    public void draw(){ background(230);

    }

  • I have the poweeeeeer! (Heman)

  • Man... right after he got fire from Promethius.

No public wish lists :(