Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Manvi Mittal
- * Combination of LCD and Motor
- */
- #include <LiquidCrystal.h>
- LiquidCrystal lcd (10, 19, 11, 12, 13, 7);
- const int photoPin = A3;
- int photoVal = 0;
- const int controlPin1 = 2;
- const int controlPin2 = 3;
- const int enablePin = 9;
- const int directionSwitchPin = 4;
- const int onOffSwitchStateSwitchPin = 5;
- const int potPin = A0;
- int onOffSwitchState = 0;
- int previousOnOffSwitchState = 0;
- int directionSwitchState = 0;
- int previousDirectionSwitchState = 0;
- int motorEnabled = 0; //Turns the motor on/off
- int motorSpeed = 0;
- int motorDirection = 1;
- void setup() {
- // put your setup code here, to run once:
- lcd.begin (16, 2);
- for (int i = 0; i <= 11; i++)
- {
- lcd.setCursor (i, 0);
- lcd.print ("Manvi");
- delay (500);
- lcd.clear ();
- }
- pinMode (directionSwitchPin, INPUT);
- pinMode (onOffSwitchStateSwitchPin, INPUT);
- pinMode (potPin, INPUT);
- pinMode (controlPin1, OUTPUT);
- pinMode (controlPin2, OUTPUT);
- pinMode (enablePin, OUTPUT);
- Serial.begin (9600);
- digitalWrite (enablePin, LOW);
- }
- void loop() {
- // put your main code here, to run repeatedly:
- photoVal = analogRead (photoPin);
- lcd.print ("The value is:");
- lcd.setCursor (6, 1);
- lcd.print (photoVal);
- delay (200);
- lcd.clear ();
- onOffSwitchState = digitalRead (onOffSwitchStateSwitchPin); // read the value of the on/off switch
- delay (1);
- Serial.print(motorEnabled);
- directionSwitchState = digitalRead (directionSwitchPin); // read the value of the direction switch
- Serial.println (motorDirection);
- motorSpeed = analogRead (potPin) / 4; // read the value of the pot and divide by 4 to get a value
- 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 (motorEnabled == 1)
- {
- analogWrite (enablePin, motorSpeed);
- }
- else
- {
- analogWrite (enablePin, 0);
- }
- previousDirectionSwitchState = directionSwitchState;
- previousOnOffSwitchState = onOffSwitchState;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement