Controll screen state with joystick
This commit is contained in:
parent
19cd517153
commit
40beda91da
@ -6,11 +6,14 @@
|
|||||||
#include "DistSensor.cpp";
|
#include "DistSensor.cpp";
|
||||||
#include "LCDScreen.cpp";
|
#include "LCDScreen.cpp";
|
||||||
#include "CarSpotController.cpp";
|
#include "CarSpotController.cpp";
|
||||||
|
#include "JoyStickController.cpp";
|
||||||
|
|
||||||
#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
|
||||||
#define TEMP_SENSOR_PIN 9
|
#define TEMP_SENSOR_PIN 9
|
||||||
|
#define JOYSTICK_X_PIN A1
|
||||||
|
#define JOYSTICK_Y_PIN A0
|
||||||
|
|
||||||
OneWire oneWire(TEMP_SENSOR_PIN);
|
OneWire oneWire(TEMP_SENSOR_PIN);
|
||||||
DallasTemperature temperature_sensors(&oneWire);
|
DallasTemperature temperature_sensors(&oneWire);
|
||||||
@ -19,8 +22,9 @@ DistSensor dist_sensor = DistSensor(ULTRASONIC_SENSOR_PIN_TRIG, ULTRASONIC_SENSO
|
|||||||
Barrier barrier = Barrier(SERVO_PIN, 4);
|
Barrier barrier = Barrier(SERVO_PIN, 4);
|
||||||
LCDScreen screen = LCDScreen();
|
LCDScreen screen = LCDScreen();
|
||||||
CarSpotCOntroller car_spot_controller = CarSpotCOntroller(24);
|
CarSpotCOntroller car_spot_controller = CarSpotCOntroller(24);
|
||||||
|
JoySitkController joystick = JoySitkController(JOYSTICK_X_PIN, JOYSTICK_Y_PIN);
|
||||||
|
|
||||||
unsigned long current_time, sensor_last_time_activated, temperature_last_time_measured;
|
unsigned long current_time, sensor_last_time_activated, temperature_last_time_measured, joystick_last_time_activated;
|
||||||
|
|
||||||
float temperature_in_c = 0;
|
float temperature_in_c = 0;
|
||||||
|
|
||||||
@ -29,8 +33,8 @@ void setup() {
|
|||||||
dist_sensor.configure_pins();
|
dist_sensor.configure_pins();
|
||||||
barrier.configure_pins();
|
barrier.configure_pins();
|
||||||
temperature_sensors.begin();
|
temperature_sensors.begin();
|
||||||
|
joystick.configure_pins();
|
||||||
screen.init();
|
screen.init();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
@ -55,8 +59,20 @@ void loop() {
|
|||||||
temperature_in_c = temperature_sensors.getTempCByIndex(0);
|
temperature_in_c = temperature_sensors.getTempCByIndex(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
//screen.display_temperature(temperature_in_c);
|
|
||||||
|
|
||||||
screen.display_parking_spots(car_spot_controller.get_total_spots(), car_spot_controller.get_occupied_spots());
|
joystick.read();
|
||||||
|
|
||||||
|
if (joystick.is_moving_right() && current_time - joystick_last_time_activated >= 250){
|
||||||
|
joystick_last_time_activated = current_time;
|
||||||
|
|
||||||
|
screen.set_state((screen.get_next_state()));
|
||||||
|
}
|
||||||
|
if (joystick.is_moving_left() && current_time - joystick_last_time_activated >= 250){
|
||||||
|
joystick_last_time_activated = current_time;
|
||||||
|
|
||||||
|
screen.set_state(screen.get_previous_state());
|
||||||
|
}
|
||||||
|
|
||||||
|
screen.display(temperature_in_c,car_spot_controller.get_total_spots(), car_spot_controller.get_occupied_spots());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user