Pages: 1 [2]   Go Down
Author Topic: Vibrating Motors - HELP  (Read 1714 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Or does it not really matter, and i'm making something out of nothing here?
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 635
Posts: 34572
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 635
Posts: 34572
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Any ideas why?
Yes, your code is wrong.

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here it is. I know it could do with arrays instead.

Code:
// 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 PINS
const 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 PUSHBUTTONS
int pushbuttonState1 = 0;
int pushbuttonState2 = 0;
int pushbuttonState3 = 0;
int pushbuttonState4 = 0;
int pushbuttonState5 = 0;
int pushbuttonState6 = 0;

// CURRENT STATE OF RELAYS
int 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);
  }

}
Logged

New Jersey
Online Online
Faraday Member
**
Karma: 70
Posts: 3741
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Pages: 1 [2]   Go Up
Jump to: