Go Down

### Topic: Vibrating Motors - HELP (Read 4101 times)previous topic - next topic

#### JM3000

#15
##### Apr 15, 2012, 07:59 pm
Or does it not really matter, and i'm making something out of nothing here?

#### Grumpy_Mike

#16
##### Apr 15, 2012, 11:02 pm
Quote
Or does it not really matter,

It doesn't matter.

Quote
Due to time constraints

So have we been doing your homework for you. I hope we get a good mark.

#### JM3000

#17
##### Apr 16, 2012, 09:50 pm
No, just giving me a nudge or two in the right direction.

Having uploaded my code and made a circuit, my board is doing something a bit weird.

I've programmed the board so that it only gives an output when one of the buttons is pressed and does nothing when no buttons are pressed, but at the moment it seems to ignore any of the button presses, and just cycles through each of the things that the buttons would do, but without any of them being pressed. Any ideas why?

#### Grumpy_Mike

#18
##### Apr 16, 2012, 11:16 pm
Quote
Any ideas why?

However in order to tell you exactly exactly what bit of it is wrong you will have to post it as my crystal ball is on the blink at the moment.

#### JM3000

#19
##### Apr 16, 2012, 11:51 pm
Here it is. I know it could do with arrays instead.

Code: [Select]
`// SETS PUSHBUTTON SWITCHES const int pushbutton1 = 2;const int pushbutton2 = 3;const int pushbutton3 = 4;const int pushbutton4 = 5;const int pushbutton5 = 6;const int pushbutton6 = 7;// SETS RELAY PINSconst int relayCT = 10;const int relayL1 = 11;const int relayL2 = 12;const int relayL3 = 13;const int relayL4 = 14;const int relayCB = 15;const int relayR1 = 16;const int relayR2 = 17;const int relayR3 = 18;const int relayR4 = 19;// CURRENT STATE OF PUSHBUTTONSint pushbuttonState1 = 0;int pushbuttonState2 = 0;int pushbuttonState3 = 0;int pushbuttonState4 = 0;int pushbuttonState5 = 0;int pushbuttonState6 = 0;// CURRENT STATE OF RELAYSint relayStateCT = 0;int relayStateL1 = 0;int relayStateL2 = 0;int relayStateL3 = 0;int relayStateL4 = 0;int relayStateCB = 0;int relayStateR1 = 0;int relayStateR2 = 0;int relayStateR3= 0;int relayStateR4 = 0;void setup() {     // pushbuttons as inputs      pinMode(pushbutton1, INPUT);   pinMode(pushbutton2, INPUT);   pinMode(pushbutton3, INPUT);   pinMode(pushbutton4, INPUT);   pinMode(pushbutton5, INPUT);   pinMode(pushbutton6, INPUT);      // relays as outputs      pinMode(relayCT, OUTPUT);   pinMode(relayL1, OUTPUT);   pinMode(relayL2, OUTPUT);   pinMode(relayL3, OUTPUT);   pinMode(relayL4, OUTPUT);   pinMode(relayCB, OUTPUT);   pinMode(relayR1, OUTPUT);   pinMode(relayR2, OUTPUT);   pinMode(relayR3, OUTPUT);   pinMode(relayR4, OUTPUT);                }void loop() {    // reads state of each push button    pushbuttonState1 = digitalRead(pushbutton1);  pushbuttonState2 = digitalRead(pushbutton2);  pushbuttonState3 = digitalRead(pushbutton3);  pushbuttonState4 = digitalRead(pushbutton4);  pushbuttonState5 = digitalRead(pushbutton5);  pushbuttonState6 = digitalRead(pushbutton6);    // ----------RIGHT TURN------------    if (  pushbuttonState1 == true     ){          digitalWrite(relayR2, HIGH);           digitalWrite(relayR3, HIGH);         digitalWrite(relayR4, HIGH);      delay(250);      digitalWrite(relayR2, LOW);           digitalWrite(relayR3, LOW) ;          digitalWrite(relayR4, LOW);      delay(250);      digitalWrite(relayR2, HIGH);           digitalWrite(relayR3, HIGH) ;          digitalWrite(relayR4, HIGH);      delay(250);      digitalWrite(relayR2, LOW);           digitalWrite(relayR3, LOW) ;           digitalWrite(relayR4, LOW);      delay(500);        } // -----------LEFT TURN-------------- if (     pushbuttonState2 == true    ){       digitalWrite(relayL2, HIGH)  ;         digitalWrite(relayL3, HIGH)  ;        digitalWrite(relayL4, HIGH);      delay(250);      digitalWrite(relayL2, LOW) ;          digitalWrite(relayL3, LOW)  ;          digitalWrite(relayL4, LOW);      delay(250);      digitalWrite(relayL2, HIGH);           digitalWrite(relayL3, HIGH) ;          digitalWrite(relayL4, HIGH);      delay(250);      digitalWrite(relayL2, LOW) ;          digitalWrite(relayL3, LOW) ;          digitalWrite(relayL4, LOW);      delay(500);      }  // ----------ROUNDABOUT 1st EXIT---------    if (     pushbuttonState3 == true    ){        //circle1 = start      digitalWrite(relayCB, HIGH);      delay(80);      digitalWrite(relayCB, LOW);      digitalWrite(relayL4, HIGH);      delay(80);      digitalWrite(relayL4, LOW);      digitalWrite(relayL3, HIGH);      delay(80);      digitalWrite(relayL3, LOW);      digitalWrite(relayL2, HIGH);      delay(80);      digitalWrite(relayL2, LOW);      digitalWrite(relayL1, HIGH);      delay(80);      digitalWrite(relayL1, LOW);      digitalWrite(relayCT, HIGH);      delay(80);      digitalWrite(relayCT, LOW);      digitalWrite(relayR1, HIGH);      delay(80);      digitalWrite(relayR1, LOW);      digitalWrite(relayR2, HIGH);      delay(80);      digitalWrite(relayR2, LOW);      digitalWrite(relayR3, HIGH);      delay(80);      digitalWrite(relayR3, LOW);      digitalWrite(relayR4, HIGH);      delay(80);      digitalWrite(relayR4, LOW);      delay(200);      //circle1 = end      digitalWrite(relayCB, HIGH);      delay(80);      digitalWrite(relayCB, LOW);      digitalWrite(relayL4, HIGH);      delay(80);      digitalWrite(relayL4, LOW);      digitalWrite(relayL3, HIGH);      delay(80);      digitalWrite(relayL3, LOW);      digitalWrite(relayL2, HIGH);      delay(80);      digitalWrite(relayL2, LOW);      digitalWrite(relayL1, HIGH);      delay(80);      digitalWrite(relayL1, LOW);      digitalWrite(relayCT, HIGH);      delay(80);      digitalWrite(relayCT, LOW);      digitalWrite(relayR1, HIGH);      delay(80);      digitalWrite(relayR1, LOW);      digitalWrite(relayR2, HIGH);      delay(80);      digitalWrite(relayR2, LOW);      digitalWrite(relayR3, HIGH);      delay(80);      digitalWrite(relayR3, LOW);      digitalWrite(relayR4, HIGH);      delay(80);      digitalWrite(relayR4, LOW);      delay(200);      //circle2 = end                                      digitalWrite(relayL2, HIGH);           digitalWrite(relayL3, HIGH) ;           digitalWrite(relayL4, HIGH);      delay(125);      digitalWrite(relayL2, LOW);           digitalWrite(relayL3, LOW) ;           digitalWrite(relayL4, LOW);      delay(125);      digitalWrite(relayL2, HIGH);           digitalWrite(relayL3, HIGH) ;          digitalWrite(relayL4, HIGH);      delay(125);      digitalWrite(relayL2, LOW);           digitalWrite(relayL3, LOW) ;           digitalWrite(relayL4, LOW);      delay(500);        }          // ----------ROUNDABOUT 2nd EXIT---------  if (     pushbuttonState4 == true    ){        //circle1 = start     digitalWrite(relayCB, HIGH);      delay(80);      digitalWrite(relayCB, LOW);      digitalWrite(relayL4, HIGH);      delay(80);      digitalWrite(relayL4, LOW);      digitalWrite(relayL3, HIGH);      delay(80);      digitalWrite(relayL3, LOW);      digitalWrite(relayL2, HIGH);      delay(80);      digitalWrite(relayL2, LOW);      digitalWrite(relayL1, HIGH);      delay(80);      digitalWrite(relayL1, LOW);      digitalWrite(relayCT, HIGH);      delay(80);      digitalWrite(relayCT, LOW);      digitalWrite(relayR1, HIGH);      delay(80);      digitalWrite(relayR1, LOW);      digitalWrite(relayR2, HIGH);      delay(80);      digitalWrite(relayR2, LOW);      digitalWrite(relayR3, HIGH);      delay(80);      digitalWrite(relayR3, LOW);      digitalWrite(relayR4, HIGH);      delay(80);      digitalWrite(relayR4, LOW);      delay(200);      //circle1 = end      digitalWrite(relayCB, HIGH);      delay(80);      digitalWrite(relayCB, LOW);      digitalWrite(relayL4, HIGH);      delay(80);      digitalWrite(relayL4, LOW);      digitalWrite(relayL3, HIGH);      delay(80);      digitalWrite(relayL3, LOW);      digitalWrite(relayL2, HIGH);      delay(80);      digitalWrite(relayL2, LOW);      digitalWrite(relayL1, HIGH);      delay(80);      digitalWrite(relayL1, LOW);      digitalWrite(relayCT, HIGH);      delay(80);      digitalWrite(relayCT, LOW);      digitalWrite(relayR1, HIGH);      delay(80);      digitalWrite(relayR1, LOW);      digitalWrite(relayR2, HIGH);      delay(80);      digitalWrite(relayR2, LOW);      digitalWrite(relayR3, HIGH);      delay(80);      digitalWrite(relayR3, LOW);      digitalWrite(relayR4, HIGH);      delay(80);      digitalWrite(relayR4, LOW);      delay(200);      //circle2 = end       //2nd exit signal      digitalWrite(relayL1, HIGH);          digitalWrite(relayCT, HIGH) ;           digitalWrite(relayR1, HIGH);      delay(125);      digitalWrite(relayL1, LOW);           digitalWrite(relayCT, LOW) ;           digitalWrite(relayR1, LOW);      delay(125);      digitalWrite(relayL1, HIGH);           digitalWrite(relayCT, HIGH) ;          digitalWrite(relayR1, HIGH);      delay(125);      digitalWrite(relayL1, LOW);           digitalWrite(relayCT, LOW) ;           digitalWrite(relayR1, LOW);      delay(500);  }}`

#### wildbill

#20
##### Apr 16, 2012, 11:57 pm
Could be your switches are floating, giving the bogus HIGH results. How are your switches wired up - do you have the necessary pull down resistors?

Go Up