From 80c8f4815c6be36797ecb2f95c753eb90521f23e Mon Sep 17 00:00:00 2001 From: Midgard Date: Mon, 1 Feb 2021 19:18:28 +0100 Subject: [PATCH] Consistently declare pins with PIN_ constants --- lib/obus_can.cpp | 4 ++-- lib/obus_module.cpp | 24 +++++++++---------- src/controller/controller.ino | 8 +++---- .../info_serial_number/info_serial_number.ino | 17 ++++++++++++- .../needy_testmodule_buttons.ino | 11 +++++---- .../puzzle_testmodule_buttons.ino | 15 +++++++----- 6 files changed, 49 insertions(+), 30 deletions(-) diff --git a/lib/obus_can.cpp b/lib/obus_can.cpp index c688d14..69f5cd5 100644 --- a/lib/obus_can.cpp +++ b/lib/obus_can.cpp @@ -4,11 +4,11 @@ #include "obus_can.h" // Chip select for the CAN module -#define MCP_CS 8 +#define PIN_MCP_CS 8 namespace obus_can { -MCP2515 mcp2515(MCP_CS); +MCP2515 mcp2515(PIN_MCP_CS); bool is_init = false; diff --git a/lib/obus_module.cpp b/lib/obus_module.cpp index a57b41e..1c9b075 100644 --- a/lib/obus_module.cpp +++ b/lib/obus_module.cpp @@ -1,8 +1,8 @@ #include "obus_can.h" #include "obus_module.h" -#define RED_LED 4 -#define GREEN_LED 7 +#define PIN_LED_RED 4 +#define PIN_LED_GREEN 7 #define BLINK_DELAY_SLOW 1000 #define BLINK_DELAY_FAST 300 @@ -36,8 +36,8 @@ void _setLed(struct color color) { blink_delay = 0; led_reset_time = 0; - digitalWrite(RED_LED, color.red ? HIGH : LOW); - digitalWrite(GREEN_LED, color.green ? HIGH : LOW); + digitalWrite(PIN_LED_RED, color.red ? HIGH : LOW); + digitalWrite(PIN_LED_GREEN, color.green ? HIGH : LOW); } void _ledLoop() { @@ -55,11 +55,11 @@ void _ledLoop() { if (blink_delay && millis() > blink_next_time) { blink_led_lit = !blink_led_lit; if (blink_led_lit) { - digitalWrite(RED_LED, led_color.red ? HIGH : LOW); - digitalWrite(GREEN_LED, led_color.green ? HIGH : LOW); + digitalWrite(PIN_LED_RED, led_color.red ? HIGH : LOW); + digitalWrite(PIN_LED_GREEN, led_color.green ? HIGH : LOW); } else { - digitalWrite(RED_LED, false); - digitalWrite(GREEN_LED, false); + digitalWrite(PIN_LED_RED, false); + digitalWrite(PIN_LED_GREEN, false); } blink_next_time = millis() + blink_delay; @@ -83,8 +83,8 @@ void _resetState() { next_loop_call_deadline = 0; if (this_module.type == OBUS_TYPE_PUZZLE || this_module.type == OBUS_TYPE_NEEDY) { - pinMode(RED_LED, OUTPUT); - pinMode(GREEN_LED, OUTPUT); + pinMode(PIN_LED_RED, OUTPUT); + pinMode(PIN_LED_GREEN, OUTPUT); _setLedBlink(COLOR_GREEN, BLINK_DELAY_SLOW); } @@ -116,8 +116,8 @@ void empty_callback_state(uint32_t time_left, uint8_t strikes, uint8_t max_strik void blink_error(String message) { bool blink = false; while (true) { - digitalWrite(RED_LED, blink); - digitalWrite(GREEN_LED, blink); + digitalWrite(PIN_LED_RED, blink); + digitalWrite(PIN_LED_GREEN, blink); blink = !blink; delay(blink ? BLINK_DELAY_SLOW : BLINK_DELAY_FAST); Serial.println(message); diff --git a/src/controller/controller.ino b/src/controller/controller.ino index 79371c8..44407ef 100644 --- a/src/controller/controller.ino +++ b/src/controller/controller.ino @@ -56,11 +56,11 @@ struct obus_can::module this_module = { // For the display/button chip -#define STROBE_TM 4 -#define CLOCK_TM 6 -#define DIO_TM 7 +#define PIN_STROBE_TM 4 +#define PIN_CLOCK_TM 6 +#define PIN_DIO_TM 7 #define HI_FREQ false // If using a high freq CPU > ~100 MHZ set to true. -TM1638plus tm(STROBE_TM, CLOCK_TM, DIO_TM, HI_FREQ); +TM1638plus tm(PIN_STROBE_TM, PIN_CLOCK_TM, PIN_DIO_TM, HI_FREQ); Debounced startpauseButton; diff --git a/src/modules/info_serial_number/info_serial_number.ino b/src/modules/info_serial_number/info_serial_number.ino index 2e61346..2328699 100644 --- a/src/modules/info_serial_number/info_serial_number.ino +++ b/src/modules/info_serial_number/info_serial_number.ino @@ -4,13 +4,28 @@ #include #include +// Pins for the Hitachi HD44780 LCD controller +#define PIN_LCD_RS 7 // Register Select. RS=0: Command, RS=1: Data +#define PIN_LCD_ENABLE 6 // Enable (aka Clock). A falling edge on this pin triggers execution +#define PIN_LCD_D0 5 +#define PIN_LCD_D1 4 +#define PIN_LCD_D2 3 +#define PIN_LCD_D3 2 + #define SERIAL_NUMBER_SIZE 7 uint8_t serial_number[SERIAL_NUMBER_SIZE]; // true when we need to update the LCD display bool render_now = false; -LiquidCrystal lcd(7, 6, 5, 4, 3, 2); +LiquidCrystal lcd( + PIN_LCD_RS, + PIN_LCD_ENABLE, + PIN_LCD_D0, + PIN_LCD_D1, + PIN_LCD_D2, + PIN_LCD_D3 +); void setup() { diff --git a/src/modules/needy_testmodule_buttons/needy_testmodule_buttons.ino b/src/modules/needy_testmodule_buttons/needy_testmodule_buttons.ino index e42a234..5e6ac18 100644 --- a/src/modules/needy_testmodule_buttons/needy_testmodule_buttons.ino +++ b/src/modules/needy_testmodule_buttons/needy_testmodule_buttons.ino @@ -4,9 +4,10 @@ #include #include -#define SPEAKER_PIN 10 +#define PIN_GREEN_BUTTON 6 +#define PIN_SPEAKER 10 -ezButton green_button(6); +ezButton green_button(PIN_GREEN_BUTTON); void setup() { Serial.begin(115200); @@ -49,12 +50,12 @@ void loop() { // Play the appropriate sound if (trigger_time && millis() > trigger_time - 15000) { - tone(SPEAKER_PIN, 440); + tone(PIN_SPEAKER, 440); } else if (trigger_time) { - tone(SPEAKER_PIN, 449); + tone(PIN_SPEAKER, 449); } else { - noTone(SPEAKER_PIN); + noTone(PIN_SPEAKER); } } diff --git a/src/modules/puzzle_testmodule_buttons/puzzle_testmodule_buttons.ino b/src/modules/puzzle_testmodule_buttons/puzzle_testmodule_buttons.ino index 1042252..b5e920f 100644 --- a/src/modules/puzzle_testmodule_buttons/puzzle_testmodule_buttons.ino +++ b/src/modules/puzzle_testmodule_buttons/puzzle_testmodule_buttons.ino @@ -2,16 +2,19 @@ // See the LICENSE file for conditions for copying -// A red button connected to pin 5 -// A green button connected to pin 6 -// A blue led (with 330 ohm resistor) connected to pin 9 +// A red button +// A green button +// A blue led (with 330 ohm resistor) #include #include -#define BLUE_LED 9 -ezButton red_button(5); -ezButton green_button(6); +#define PIN_RED_BUTTON 5 +#define PIN_GREEN_BUTTON 6 +#define PIN_LED_BLUE 9 + +ezButton red_button(PIN_RED_BUTTON); +ezButton green_button(PIN_GREEN_BUTTON); bool blue_state = false; bool checking_input = false;