Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Servo.h>
- #define DETECT1 2 // pin 2 for sensor
- #define ACTION1 8 // pin 8 for action to do someting
- #define DETECT2 3
- #define ACTION2 13
- #define DETECT3 4
- #define ACTION3 12
- #define DETECT4 5
- #define ACTION4 16
- #define DETECT5 11
- #define ACTION5 17
- int detected;
- Servo xservo;
- Servo yservo;
- int pos = 0;
- const int XServoPin = 9;
- const int YServoPin = 10; // Servo pin that will control Y motion
- int xposPin = A0; // select the input pin for the potentiometer
- int yposPin = A1; // select the input pin for the potentiometer
- int Xpos = 0;
- int Ypos = 0;
- int buttonPin = 7;
- int buttonPress = 0;
- int laserPin = 6;
- #include <Wire.h>
- #include <LiquidCrystal_I2C.h>
- // Set the LCD address to 0x27 for a 16 chars and 2 line display
- LiquidCrystal_I2C lcd(0x27, 16, 2);
- void setup() {
- Serial.begin(9600);
- Serial.println("Robojax.com Laser Module Test");
- pinMode(DETECT1, INPUT);//define detect input pin
- pinMode(ACTION1, OUTPUT);//define ACTION output pin
- pinMode(DETECT2, INPUT);//define detect input pin
- pinMode(ACTION2, OUTPUT);//define ACTION output pin
- pinMode(DETECT3, INPUT);//define detect input pin
- pinMode(ACTION3, OUTPUT);//define ACTION output pin
- pinMode(DETECT4, INPUT);//define detect input pin
- pinMode(ACTION4, OUTPUT);//define ACTION output pin
- pinMode(DETECT5, INPUT);//define detect input pin
- pinMode(ACTION5, OUTPUT);//define ACTION output pin
- pinMode(laserPin,OUTPUT); //The laser will be an output
- pinMode(buttonPin,INPUT); //The buttonpress pin is an input
- digitalWrite(buttonPin,HIGH); //This enables the Arduino pullup for this pin
- xservo.attach(XServoPin); // attaches the servo on pin 9 to the servo object
- yservo.attach(YServoPin); // attaches the servo on pin 8 to the servo object
- // initialize the LCD
- lcd.begin();
- lcd.backlight();
- lcd.print ("shoot the sensor");
- }
- void loop() {
- buttonPress = digitalRead(buttonPin); //Read the sate of the button
- if(buttonPress == LOW) // The button press is active low , so if it is pressed we will turn the laser on
- {
- digitalWrite(laserPin, HIGH); //Turn laser on
- detected = digitalRead(DETECT1);// read Laser sensor
- if( detected == HIGH)
- {
- digitalWrite(ACTION1,HIGH);// set the buzzer ON
- Serial.println("Detected!");
- }else{
- digitalWrite(ACTION1,LOW); // Set the buzzer OFF
- Serial.println("No laser");
- // Laser Sensor code for Robojax.com
- }
- detected = digitalRead(DETECT2);// read Laser sensor
- if( detected == HIGH)
- {
- digitalWrite(ACTION2,HIGH);// set the buzzer ON
- Serial.println("Detected!");
- }else{
- digitalWrite(ACTION2,LOW); // Set the buzzer OFF
- Serial.println("No laser");
- // Laser Sensor code for Robojax.com
- }
- detected = digitalRead(DETECT3);// read Laser sensor
- if( detected == HIGH)
- {
- digitalWrite(ACTION3,HIGH);// set the buzzer ON
- Serial.println("Detected!");
- }else{
- digitalWrite(ACTION3,LOW); // Set the buzzer OFF
- Serial.println("No laser");
- // Laser Sensor code for Robojax.com
- }
- detected = digitalRead(DETECT4);// read Laser sensor
- if( detected == HIGH)
- {
- digitalWrite(ACTION4,HIGH);// set the buzzer ON
- Serial.println("Detected!");
- }else{
- digitalWrite(ACTION4,LOW); // Set the buzzer OFF
- Serial.println("No laser");
- // Laser Sensor code for Robojax.com
- }
- detected = digitalRead(DETECT5);// read Laser sensor
- if( detected == HIGH)
- {
- digitalWrite(ACTION5,HIGH);// set the buzzer ON
- Serial.println("Detected!");
- }else{
- digitalWrite(ACTION5,LOW); // Set the buzzer OFF
- Serial.println("No laser");
- // Laser Sensor code for Robojax.com
- }
- delay(200);
- } else
- {
- digitalWrite(laserPin, LOW); // If it is not pressed, keep laser off
- }
- Xpos = analogRead(xposPin); // read and store the x position location of the joystick
- Xpos = map(Xpos,0,1023,0,180); //map the analog read x values to the 0-180 servo values
- Ypos = analogRead(yposPin); // read and store the y position of the joystick
- Ypos = map(Ypos,0,1023,0,180); //map the analog read y values to the 0-180 servo values
- xservo.write(Xpos); // move the X Location servo to the x position the joystick is at
- yservo.write(Ypos);
- delay(50);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement