Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Amber
- */
- #include <LiquidCrystal.h>
- #include <Servo.h>
- Servo miServito;
- const int PotPin=A0;
- int PotVal;
- int angle;
- LiquidCrystal lcd (11, 13, 8, 10, 12, 7);
- const int photoPin = A2;
- int photoVal = 0;
- const int controlPin1 = 2;
- const int controlPin2 = 3;
- const int enablePin = 9;
- const int directionSwitchPin = 4;
- const int onOffSwitchStateSwitchPin = 6;
- const int potPin = A0;
- int onOffSwitchState = 0;
- int previousOnOffSwitchState = 0;
- int directionSwitchState = 0;
- int previousDirectionSwitchState = 0;
- int motorEnabled = 0;
- int motorSpeed = 0;
- int motorDirection = 1;
- void setup()
- {
- pinMode (PotPin, INPUT);
- miServito.attach (9);
- Serial.begin (9600);
- pinMode (potPin, INPUT);
- pinMode (directionSwitchPin, INPUT);
- pinMode (onOffSwitchStateSwitchPin, INPUT);
- pinMode (controlPin1, OUTPUT);
- pinMode (controlPin2, OUTPUT);
- pinMode (enablePin, OUTPUT);
- Serial.begin (9600);
- digitalWrite (enablePin, LOW);
- pinMode (photoPin, INPUT);
- Serial.begin (9600);
- lcd.begin (16,2);
- lcd.clear ();
- for (int counter=0; counter < 14; counter ++)
- {
- lcd.setCursor (counter, 0);
- lcd.print ("Amber");
- delay (200);
- lcd.clear ();
- }
- }
- void loop()
- {
- photoVal = analogRead (photoPin);
- lcd.print ("the value is:");
- lcd.setCursor (6, 1);
- lcd.print (photoVal);
- delay (100);
- lcd.clear ();
- onOffSwitchState = digitalRead (onOffSwitchStateSwitchPin);
- delay (1);
- directionSwitchState = digitalRead (directionSwitchPin);
- Serial.println (directionSwitchState);
- motorSpeed= analogRead (potPin);
- motorSpeed= map (motorSpeed, 0, 1023, 0, 255);
- motorSpeed = constrain (motorSpeed, 0, 255);
- if (onOffSwitchState != previousOnOffSwitchState) {
- if (onOffSwitchState == HIGH) {
- motorEnabled = !motorEnabled;
- }
- }
- if (directionSwitchState != previousDirectionSwitchState) {
- if (directionSwitchState == HIGH) {
- motorDirection = !motorDirection;
- }
- }
- if (motorDirection == 1) {
- digitalWrite (controlPin1, HIGH);
- digitalWrite (controlPin2, LOW);
- }
- else {
- digitalWrite (controlPin1, LOW);
- digitalWrite (controlPin2, HIGH);
- }
- if (motorDirection == 1) {
- analogWrite (enablePin, motorSpeed);
- }
- else {
- analogWrite (enablePin, 0);
- }
- previousDirectionSwitchState=
- directionSwitchState;
- previousOnOffSwitchState = onOffSwitchState;
- PotVal=analogRead (PotPin);
- angle= map (PotVal, 0, 1023, 0, 179);
- angle = constrain (angle, 0, 179);
- miServito.write(angle);
- //miServito.write (0);
- //delay (500);
- //
- //miServito.write (45);
- //delay (500);
- //
- //miServito.write (90);
- //delay (500);
- //
- //miServito.write (135);
- //delay (500);
- //
- //miServito.write (180);
- //delay (500);
- }
Add Comment
Please, Sign In to add comment