Add Stepper motor logic
This commit is contained in:
parent
62d95a7799
commit
a5760caad3
@ -1,6 +1,7 @@
|
|||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
#include <OneWire.h>
|
#include <OneWire.h>
|
||||||
#include <DallasTemperature.h>
|
#include <DallasTemperature.h>
|
||||||
|
#include <Stepper.h>
|
||||||
|
|
||||||
#include "Barrier.cpp";
|
#include "Barrier.cpp";
|
||||||
#include "DistSensor.cpp";
|
#include "DistSensor.cpp";
|
||||||
@ -9,7 +10,6 @@
|
|||||||
#include "JoyStickController.cpp";
|
#include "JoyStickController.cpp";
|
||||||
#include "ButtonController.cpp";
|
#include "ButtonController.cpp";
|
||||||
|
|
||||||
#define PARK_SLOTS 3
|
|
||||||
#define ULTRASONIC_SENSOR_PIN_TRIG 11
|
#define ULTRASONIC_SENSOR_PIN_TRIG 11
|
||||||
#define ULTRASONIC_SENSOR_PIN_ECHO 12
|
#define ULTRASONIC_SENSOR_PIN_ECHO 12
|
||||||
#define SERVO_PIN 10
|
#define SERVO_PIN 10
|
||||||
@ -19,16 +19,19 @@
|
|||||||
#define BUZZER_PIN 3
|
#define BUZZER_PIN 3
|
||||||
#define BUTTON_PIN 8
|
#define BUTTON_PIN 8
|
||||||
|
|
||||||
|
#define PARK_SLOTS 3
|
||||||
|
#define STEP_MOTOR_STEPS 200
|
||||||
|
|
||||||
OneWire oneWire(TEMP_SENSOR_PIN);
|
OneWire oneWire(TEMP_SENSOR_PIN);
|
||||||
DallasTemperature temperature_sensors(&oneWire);
|
DallasTemperature temperature_sensors(&oneWire);
|
||||||
|
|
||||||
DistSensor dist_sensor = DistSensor(ULTRASONIC_SENSOR_PIN_TRIG, ULTRASONIC_SENSOR_PIN_ECHO, 25.0);
|
DistSensor dist_sensor = DistSensor(ULTRASONIC_SENSOR_PIN_TRIG, ULTRASONIC_SENSOR_PIN_ECHO, 25.0);
|
||||||
Barrier barrier = Barrier(SERVO_PIN, 2);
|
Barrier barrier = Barrier(SERVO_PIN, 2);
|
||||||
LCDScreen screen = LCDScreen();
|
LCDScreen screen = LCDScreen();
|
||||||
CarSpotController car_spot_controller = CarSpotController(2);
|
CarSpotController car_spot_controller = CarSpotController(PARK_SLOTS);
|
||||||
JoystickController joystick = JoystickController(JOYSTICK_X_PIN, JOYSTICK_Y_PIN);
|
JoystickController joystick = JoystickController(JOYSTICK_X_PIN, JOYSTICK_Y_PIN);
|
||||||
ButtonController button = ButtonController(BUTTON_PIN);
|
ButtonController button = ButtonController(BUTTON_PIN);
|
||||||
|
Stepper stepper(STEP_MOTOR_STEPS, 6, 5, 4, 2);
|
||||||
|
|
||||||
unsigned long current_time, sensor_last_time_readed, barrier_last_time_opened, temperature_last_time_measured, joystick_last_time_activated, joystick_last_time_readed, screen_last_time_updated;
|
unsigned long current_time, sensor_last_time_readed, barrier_last_time_opened, temperature_last_time_measured, joystick_last_time_activated, joystick_last_time_readed, screen_last_time_updated;
|
||||||
|
|
||||||
@ -41,6 +44,7 @@ void setup() {
|
|||||||
temperature_sensors.begin();
|
temperature_sensors.begin();
|
||||||
joystick.configure_pins();
|
joystick.configure_pins();
|
||||||
button.configure_pins();
|
button.configure_pins();
|
||||||
|
stepper.setSpeed(60);
|
||||||
screen.init();
|
screen.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,6 +59,7 @@ void loop() {
|
|||||||
barrier_last_time_opened = current_time;
|
barrier_last_time_opened = current_time;
|
||||||
if (!car_spot_controller.is_empty() && barrier.is_closed()){
|
if (!car_spot_controller.is_empty() && barrier.is_closed()){
|
||||||
barrier.open();
|
barrier.open();
|
||||||
|
stepper.step(STEP_MOTOR_STEPS);
|
||||||
car_spot_controller.decrement_occupied_spots();
|
car_spot_controller.decrement_occupied_spots();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -66,6 +71,7 @@ void loop() {
|
|||||||
if (!car_spot_controller.is_full()){
|
if (!car_spot_controller.is_full()){
|
||||||
barrier.open();
|
barrier.open();
|
||||||
car_spot_controller.increment_occupied_spots();
|
car_spot_controller.increment_occupied_spots();
|
||||||
|
stepper.step(STEP_MOTOR_STEPS);
|
||||||
}else{
|
}else{
|
||||||
tone(BUZZER_PIN, 262, 500);
|
tone(BUZZER_PIN, 262, 500);
|
||||||
}
|
}
|
||||||
@ -73,6 +79,7 @@ void loop() {
|
|||||||
} else if (!dist_sensor.is_in_range() && barrier.is_open()){
|
} else if (!dist_sensor.is_in_range() && barrier.is_open()){
|
||||||
if (current_time - barrier_last_time_opened >= barrier.open_time_seconds * 1000 && !button.is_pressed()){
|
if (current_time - barrier_last_time_opened >= barrier.open_time_seconds * 1000 && !button.is_pressed()){
|
||||||
barrier.close();
|
barrier.close();
|
||||||
|
stepper.step(-STEP_MOTOR_STEPS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user