//Include the servo library so the servomotor can be controlled
#include <Servo.h>
//create a servo object, named 'laserServo'
Servo laserServo;
//intitialise Global variable
int Potentiometer = A0;
int LDR = A5;
int Switch = 7;
int LDRLed = 3;
int PotLed = 5;
int SwitchLed = 6;
int Motor = 9;
//integers for laser angle variable and endpoint
int laserAngle = 0;
int laserPeak = 0;
//***STAGE #1 - define your variables here ***
void setup() {
//initialise servo (this is done for you)
laserServo.attach(9); //attach servo to pin 9
//***STAGE #2 - setup your system here ***
pinMode(LDR, INPUT);
pinMode(Potentiometer, INPUT);
pinMode(Switch, INPUT_PULLUP);
pinMode(LDRLed, OUTPUT);
pinMode(PotLed, OUTPUT);
pinMode(SwitchLed, OUTPUT);
pinMode(Motor, OUTPUT);
//begin serial transmissions (for sending information back)
Serial.begin(9600);
}
void loop() {
//Call User Defined Function to move the laser (leave this function to keep the servo moving!)
//***STAGE #3a - read sensors here ***
int PotVal = analogRead(Potentiometer)/4;
int SwitchVal = digitalRead(Switch);
int LDRVal = analogRead(LDR);
//***STAGE #3b - read sensors here ***
analogWrite(PotLed, PotVal);
analogWrite(LDRLed, LDRVal);
digitalWrite(SwitchLed, SwitchVal);
analogWrite(Motor, PotVal);
delay(30); //delay which defines how fast you loop to read your sensors...
Serial.print(PotVal); Serial.print(",");Serial.print(SwitchVal); Serial.print(",");Serial.print(LDRVal);
Serial.print('\n');
}
//User Defined Function to move the laser