Hi good people of Arduino forum, I hope U can help me.
I am building table tennis robot, and I need to make some cool drills with it.
I want to control movement of tube (servo motor - left right)
This is my starting point
And code:
/*
IR Breakbeam sensor demo!
*/
#define LEDPIN 13
// Pin 13: Arduino has an LED connected on pin 13
#define SENSORPIN 4
// variables will change:
int sensorState = 0, lastState=0; // variable for reading the pushbutton status
void setup() {
// initialize the LED pin as an output:
pinMode(LEDPIN, OUTPUT);
// initialize the sensor pin as an input:
pinMode(SENSORPIN, INPUT);
digitalWrite(SENSORPIN, HIGH); // turn on the pullup
Serial.begin(9600);
}
void loop(){
// read the state of the pushbutton value:
sensorState = digitalRead(SENSORPIN);
// check if the sensor beam is broken
// if it is, the sensorState is LOW:
if (sensorState == LOW) {
// turn LED on:
digitalWrite(LEDPIN, HIGH);
}
else {
// turn LED off:
digitalWrite(LEDPIN, LOW);
}
if (sensorState && !lastState) {
Serial.println("Unbroken");
}
if (!sensorState && lastState) {
Serial.println("Broken");
}
lastState = sensorState;
}
What I need?
Sensor is atached to the the ending point of tube, where ping pong ball fly out.
- When Ball 1 fly out sensor give signal to arduino and servo motor goes to position 1.
- servoLeft.write(20,255,false);
- When Ball 2 fly out sensor give signal to arduino and servo motor goes to position 0.
- servoLeft.write(0,255,false);
- I need this cycle for 6 balls (left rigt, left right, left right) and then pause
- delay(4000);
- And then we go again, this left right drill
I know this is not so hard to do it, but I am not programmer, and I need your help.
Thanks