Parking lot / College Capstone Project


what have 2 servo motors, , 2 photo-electric switches. want (switch_1) activate (servo_1) , (switch_2) activate (servo_2). each of these need go 0-90 degrees when high. think problem in "if statement " may wrong. if 1 of servos , switches works fine. both doesn't.  switches powered external 12v , servos powered external 5v.

thanks in advance!!

code below




code: [select]

#include <servo.h>

servo servo1;  // create servo object control servo @ entrance

servo servo2;  // create servo object control servo @ exit



const int switch1pin = 7;     // number of photoelectric switch pin @ entrance

int switch1state = 0;         // variable reading photoelectric switch @ entrance


const int switch2pin = 3;     // number of photoelectric switch pin @ exit

int switch2state = 0;         // variable reading photoelectric switch @ exit

               
void setup()

{
 
 pinmode(switch1pin, input);  
 
 pinmode(switch2pin, input);

 servo1.attach(9);  // attaches servo on pin 9 output of photoelectric switch @ entrance
 
 servo2.attach(11);  // attaches servo on pin 11 output of photoelectric switch @ exit
}

void loop(){
 // read state of photoelectric switch value:
 switch1state = digitalread(switch1pin);
 switch2state = digitalread(switch2pin);
 


 // check if 1st switch pressed.
 // if is, 1st switch high:
 if (switch1state == high)
 
 
{      
   servo1.write(90);              // tell servo go upper position  
 
 }
 else {
 
   servo1.write(0);             //delay 5 seconds , go zero
   delay(5000);
 
 }
 if (switch2state == high)
 
 
{      
   servo2.write(90);              // tell servo go upper position  
 
 }
 else {
 
   servo2.write(0);             //delay 5 seconds , go zero
   delay(5000);

here problems see:

1)  need learn post code between code tags.  these generated "#" button.
2)  did not set starting position servos.  maybe servo.attach(...) you, don't know.
3)  comments "delay 5 seconds , go starting position" go position 0 (the starting position?) , delay 5 seconds.
4)  delay(...) blocking operation.  means nothing else can happen while delay in progress.  thus, delay(5000) means 5 seconds switches not read, other servo cannot handled, etc.  suggested @ point avoid delay(...) statements , embrace "blink without delay" example.

maybe have works not being sufficiently patient (5 seconds worth!) during testing?



Arduino Forum > Using Arduino > Programming Questions > Parking lot / College Capstone Project


arduino

Comments

Popular posts from this blog

VIDIOC_S_FMT error 16, Device or resource busy - Raspberry Pi Forums

using a laptop skeleton to build a pi laptop - Raspberry Pi Forums

Forum for Joomla? - Joomla! Forum - community, help and support