diff --git a/bigass_7_segment/lib_fp/bird_with_pants_small.kicad_mod b/bigass_7_segment/lib_fp/bird_with_pants_small.kicad_mod index 2af6602..53898af 100644 --- a/bigass_7_segment/lib_fp/bird_with_pants_small.kicad_mod +++ b/bigass_7_segment/lib_fp/bird_with_pants_small.kicad_mod @@ -1,11 +1,11 @@ -(module bird_with_pants_small (layer F.Cu) (tedit 5D6D8673) - (fp_text reference G*** (at 0 0) (layer F.SilkS) hide - (effects (font (size 1.524 1.524) (thickness 0.3))) - ) - (fp_text value LOGO (at 0.75 0) (layer F.SilkS) hide - (effects (font (size 1.524 1.524) (thickness 0.3))) - ) - (fp_poly (pts (xy -1.143 -1.524) (xy 0.4445 -1.524) (xy 1.2192 0.5715) (xy -0.5334 0.5715) - (xy -0.7874 -1.143)) (layer F.SilkS) (width 0.1)) - (fp_poly (pts (xy -0.4953 0.8255) (xy 1.3208 0.8255) (xy 1.6002 1.5875) (xy -0.381 1.5875)) (layer F.SilkS) (width 0.1)) -) +(module bird_with_pants_small (layer F.Cu) (tedit 5D6D8673) + (fp_text reference G*** (at 0 0) (layer F.SilkS) hide + (effects (font (size 1.524 1.524) (thickness 0.3))) + ) + (fp_text value LOGO (at 0.75 0) (layer F.SilkS) hide + (effects (font (size 1.524 1.524) (thickness 0.3))) + ) + (fp_poly (pts (xy -1.143 -1.524) (xy 0.4445 -1.524) (xy 1.2192 0.5715) (xy -0.5334 0.5715) + (xy -0.7874 -1.143)) (layer F.SilkS) (width 0.1)) + (fp_poly (pts (xy -0.4953 0.8255) (xy 1.3208 0.8255) (xy 1.6002 1.5875) (xy -0.381 1.5875)) (layer F.SilkS) (width 0.1)) +) diff --git a/bigass_7_segment/lib_fp/bird_with_pants_small_flipped.kicad_mod b/bigass_7_segment/lib_fp/bird_with_pants_small_flipped.kicad_mod index 839db26..f4b883e 100644 --- a/bigass_7_segment/lib_fp/bird_with_pants_small_flipped.kicad_mod +++ b/bigass_7_segment/lib_fp/bird_with_pants_small_flipped.kicad_mod @@ -1,11 +1,11 @@ -(module bird_with_pants_small_flipped (layer F.Cu) (tedit 5D6EE17B) - (fp_text reference G*** (at 0 0) (layer F.SilkS) hide - (effects (font (size 1.524 1.524) (thickness 0.3))) - ) - (fp_text value LOGO (at 0.75 0) (layer F.SilkS) hide - (effects (font (size 1.524 1.524) (thickness 0.3))) - ) - (fp_poly (pts (xy 1.143 -1.524) (xy -0.4445 -1.524) (xy -1.2192 0.5715) (xy 0.5334 0.5715) - (xy 0.7874 -1.143)) (layer F.SilkS) (width 0.1)) - (fp_poly (pts (xy 0.4953 0.8255) (xy -1.3208 0.8255) (xy -1.6002 1.5875) (xy 0.381 1.5875)) (layer F.SilkS) (width 0.1)) -) +(module bird_with_pants_small_flipped (layer F.Cu) (tedit 5D6EE17B) + (fp_text reference G*** (at 0 0) (layer F.SilkS) hide + (effects (font (size 1.524 1.524) (thickness 0.3))) + ) + (fp_text value LOGO (at 0.75 0) (layer F.SilkS) hide + (effects (font (size 1.524 1.524) (thickness 0.3))) + ) + (fp_poly (pts (xy 1.143 -1.524) (xy -0.4445 -1.524) (xy -1.2192 0.5715) (xy 0.5334 0.5715) + (xy 0.7874 -1.143)) (layer F.SilkS) (width 0.1)) + (fp_poly (pts (xy 0.4953 0.8255) (xy -1.3208 0.8255) (xy -1.6002 1.5875) (xy 0.381 1.5875)) (layer F.SilkS) (width 0.1)) +) diff --git a/code/.vscode/arduino.json b/code/.vscode/arduino.json index 14858f2..e76f67d 100644 --- a/code/.vscode/arduino.json +++ b/code/.vscode/arduino.json @@ -1,5 +1,5 @@ -{ - "programmer": "USBasp", - "board": "arduino:avr:nano", - "configuration": "cpu=atmega328" +{ + "programmer": "USBasp", + "board": "arduino:avr:nano", + "configuration": "cpu=atmega328" } \ No newline at end of file diff --git a/code/.vscode/c_cpp_properties.json b/code/.vscode/c_cpp_properties.json index 82df28b..86ab690 100644 --- a/code/.vscode/c_cpp_properties.json +++ b/code/.vscode/c_cpp_properties.json @@ -1,23 +1,23 @@ -{ - "configurations": [ - { - "name": "Mac", - "includePath": [ - "/Applications/Arduino.app/Contents/Java/tools/**", - "/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/**" - ], - "forcedInclude": [ - "/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Arduino.h" - ], - "macFrameworkPath": [ - "/System/Library/Frameworks", - "/Library/Frameworks" - ], - "intelliSenseMode": "clang-x64", - "compilerPath": "/usr/local/bin/gcc-9", - "cStandard": "gnu18", - "cppStandard": "gnu++14" - } - ], - "version": 4 +{ + "configurations": [ + { + "name": "Mac", + "includePath": [ + "/Applications/Arduino.app/Contents/Java/tools/**", + "/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/**" + ], + "forcedInclude": [ + "/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Arduino.h" + ], + "macFrameworkPath": [ + "/System/Library/Frameworks", + "/Library/Frameworks" + ], + "intelliSenseMode": "clang-x64", + "compilerPath": "/usr/local/bin/gcc-9", + "cStandard": "gnu18", + "cppStandard": "gnu++14" + } + ], + "version": 4 } \ No newline at end of file diff --git a/code/radar_speed_sign/.gitignore b/code/radar_speed_sign/.gitignore index 89cc49c..5762142 100644 --- a/code/radar_speed_sign/.gitignore +++ b/code/radar_speed_sign/.gitignore @@ -1,5 +1,5 @@ -.pio -.vscode/.browse.c_cpp.db* -.vscode/c_cpp_properties.json -.vscode/launch.json -.vscode/ipch +.pio +.vscode/.browse.c_cpp.db* +.vscode/c_cpp_properties.json +.vscode/launch.json +.vscode/ipch diff --git a/code/radar_speed_sign/include/README b/code/radar_speed_sign/include/README index 194dcd4..45496b1 100644 --- a/code/radar_speed_sign/include/README +++ b/code/radar_speed_sign/include/README @@ -1,39 +1,39 @@ - -This directory is intended for project header files. - -A header file is a file containing C declarations and macro definitions -to be shared between several project source files. You request the use of a -header file in your project source file (C, C++, etc) located in `src` folder -by including it, with the C preprocessing directive `#include'. - -```src/main.c - -#include "header.h" - -int main (void) -{ - ... -} -``` - -Including a header file produces the same results as copying the header file -into each source file that needs it. Such copying would be time-consuming -and error-prone. With a header file, the related declarations appear -in only one place. If they need to be changed, they can be changed in one -place, and programs that include the header file will automatically use the -new version when next recompiled. The header file eliminates the labor of -finding and changing all the copies as well as the risk that a failure to -find one copy will result in inconsistencies within a program. - -In C, the usual convention is to give header files names that end with `.h'. -It is most portable to use only letters, digits, dashes, and underscores in -header file names, and at most one dot. - -Read more about using header files in official GCC documentation: - -* Include Syntax -* Include Operation -* Once-Only Headers -* Computed Includes - -https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html + +This directory is intended for project header files. + +A header file is a file containing C declarations and macro definitions +to be shared between several project source files. You request the use of a +header file in your project source file (C, C++, etc) located in `src` folder +by including it, with the C preprocessing directive `#include'. + +```src/main.c + +#include "header.h" + +int main (void) +{ + ... +} +``` + +Including a header file produces the same results as copying the header file +into each source file that needs it. Such copying would be time-consuming +and error-prone. With a header file, the related declarations appear +in only one place. If they need to be changed, they can be changed in one +place, and programs that include the header file will automatically use the +new version when next recompiled. The header file eliminates the labor of +finding and changing all the copies as well as the risk that a failure to +find one copy will result in inconsistencies within a program. + +In C, the usual convention is to give header files names that end with `.h'. +It is most portable to use only letters, digits, dashes, and underscores in +header file names, and at most one dot. + +Read more about using header files in official GCC documentation: + +* Include Syntax +* Include Operation +* Once-Only Headers +* Computed Includes + +https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html diff --git a/code/radar_speed_sign/include/hb100.hh b/code/radar_speed_sign/include/hb100.hh index 605fc73..1ebdec6 100644 --- a/code/radar_speed_sign/include/hb100.hh +++ b/code/radar_speed_sign/include/hb100.hh @@ -1,22 +1,22 @@ -#ifndef HB100_H -#define HB100_H - -#include - -#define SPEED_BUF_SIZE 100 - -class HB100 { - public: - // sad sad, these are exposed because I need to hit them in an ISR - volatile uint32_t last_pulse_period{0}; - volatile uint32_t last_pulse_us{0}; - - HB100(){} - - uint16_t calc_speed(); - private: - uint16_t _speed_buf[SPEED_BUF_SIZE] = {0}; - size_t _speed_buf_index = 0; -}; - +#ifndef HB100_H +#define HB100_H + +#include + +#define SPEED_BUF_SIZE 100 + +class HB100 { + public: + // sad sad, these are exposed because I need to hit them in an ISR + volatile uint32_t last_pulse_period{0}; + volatile uint32_t last_pulse_us{0}; + + HB100(){} + + uint16_t calc_speed(); + private: + uint16_t _speed_buf[SPEED_BUF_SIZE] = {0}; + size_t _speed_buf_index = 0; +}; + #endif /* HB100_H */ \ No newline at end of file diff --git a/code/radar_speed_sign/include/seven_seg.hh b/code/radar_speed_sign/include/seven_seg.hh index 84151d3..8bb73ee 100644 --- a/code/radar_speed_sign/include/seven_seg.hh +++ b/code/radar_speed_sign/include/seven_seg.hh @@ -1,53 +1,53 @@ -#ifndef SEVEN_SEG_H -#define SEVEN_SEG_H - -#include -#include - -#define SPI_RCLK_PIN_DEFAULT 10 -#define SPI_RATE_HZ_DEFAULT 1400000 - -// Little Endian -#define SEVEN_SEG_0 0b00111111 //11111100 -#define SEVEN_SEG_1 0b00000110 //01100000 -#define SEVEN_SEG_2 0b01011011 //11011010 -#define SEVEN_SEG_3 0b01001111 //11110010 -#define SEVEN_SEG_4 0b01100110 //01100110 -#define SEVEN_SEG_5 0b01101101 //10110100 -#define SEVEN_SEG_6 0b01111101 //10111110 -#define SEVEN_SEG_7 0b00000111 //11100000 -#define SEVEN_SEG_8 0b01111111 //11111110 -#define SEVEN_SEG_9 0b01101111 //11110110 -#define SEVEN_SEG_F 0b01110001 //10001100 -#define SEVEN_SEG_BLANK 0x00 - -// Big Endian -// #define SEVEN_SEG_0 0b11111100 -// #define SEVEN_SEG_1 0b01100000 -// #define SEVEN_SEG_2 0b11011010 -// #define SEVEN_SEG_3 0b11110010 -// #define SEVEN_SEG_4 0b01100110 -// #define SEVEN_SEG_5 0b10110100 -// #define SEVEN_SEG_6 0b10111110 -// #define SEVEN_SEG_7 0b11100000 -// #define SEVEN_SEG_8 0b11111110 -// #define SEVEN_SEG_9 0b11110110 -// #define SEVEN_SEG_F 0b10001100 - -class SevenSeg { - public: - SevenSeg(uint8_t spi_rclk_pin = SPI_RCLK_PIN_DEFAULT, uint32_t spi_rate_hz = SPI_RATE_HZ_DEFAULT) - : _spi_rclk_pin(spi_rclk_pin) - , _spi_rate_hz(spi_rate_hz) {} - void init(); - void write(uint8_t value, bool decimal=false); - - private: - uint8_t _spi_rclk_pin; - uint32_t _spi_rate_hz; - - uint8_t digit_to_seg(uint8_t digit, bool decimal=false); - -}; - +#ifndef SEVEN_SEG_H +#define SEVEN_SEG_H + +#include +#include + +#define SPI_RCLK_PIN_DEFAULT 10 +#define SPI_RATE_HZ_DEFAULT 1400000 + +// Little Endian +#define SEVEN_SEG_0 0b00111111 //11111100 +#define SEVEN_SEG_1 0b00000110 //01100000 +#define SEVEN_SEG_2 0b01011011 //11011010 +#define SEVEN_SEG_3 0b01001111 //11110010 +#define SEVEN_SEG_4 0b01100110 //01100110 +#define SEVEN_SEG_5 0b01101101 //10110100 +#define SEVEN_SEG_6 0b01111101 //10111110 +#define SEVEN_SEG_7 0b00000111 //11100000 +#define SEVEN_SEG_8 0b01111111 //11111110 +#define SEVEN_SEG_9 0b01101111 //11110110 +#define SEVEN_SEG_F 0b01110001 //10001100 +#define SEVEN_SEG_BLANK 0x00 + +// Big Endian +// #define SEVEN_SEG_0 0b11111100 +// #define SEVEN_SEG_1 0b01100000 +// #define SEVEN_SEG_2 0b11011010 +// #define SEVEN_SEG_3 0b11110010 +// #define SEVEN_SEG_4 0b01100110 +// #define SEVEN_SEG_5 0b10110100 +// #define SEVEN_SEG_6 0b10111110 +// #define SEVEN_SEG_7 0b11100000 +// #define SEVEN_SEG_8 0b11111110 +// #define SEVEN_SEG_9 0b11110110 +// #define SEVEN_SEG_F 0b10001100 + +class SevenSeg { + public: + SevenSeg(uint8_t spi_rclk_pin = SPI_RCLK_PIN_DEFAULT, uint32_t spi_rate_hz = SPI_RATE_HZ_DEFAULT) + : _spi_rclk_pin(spi_rclk_pin) + , _spi_rate_hz(spi_rate_hz) {} + void init(); + void write(uint8_t value, bool decimal=false); + + private: + uint8_t _spi_rclk_pin; + uint32_t _spi_rate_hz; + + uint8_t digit_to_seg(uint8_t digit, bool decimal=false); + +}; + #endif /* SEVEN_SEG_H */ \ No newline at end of file diff --git a/code/radar_speed_sign/lib/README b/code/radar_speed_sign/lib/README index 6debab1..8c9c29c 100644 --- a/code/radar_speed_sign/lib/README +++ b/code/radar_speed_sign/lib/README @@ -1,46 +1,46 @@ - -This directory is intended for project specific (private) libraries. -PlatformIO will compile them to static libraries and link into executable file. - -The source code of each library should be placed in a an own separate directory -("lib/your_library_name/[here are source files]"). - -For example, see a structure of the following two libraries `Foo` and `Bar`: - -|--lib -| | -| |--Bar -| | |--docs -| | |--examples -| | |--src -| | |- Bar.c -| | |- Bar.h -| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html -| | -| |--Foo -| | |- Foo.c -| | |- Foo.h -| | -| |- README --> THIS FILE -| -|- platformio.ini -|--src - |- main.c - -and a contents of `src/main.c`: -``` -#include -#include - -int main (void) -{ - ... -} - -``` - -PlatformIO Library Dependency Finder will find automatically dependent -libraries scanning project source files. - -More information about PlatformIO Library Dependency Finder -- https://docs.platformio.org/page/librarymanager/ldf.html + +This directory is intended for project specific (private) libraries. +PlatformIO will compile them to static libraries and link into executable file. + +The source code of each library should be placed in a an own separate directory +("lib/your_library_name/[here are source files]"). + +For example, see a structure of the following two libraries `Foo` and `Bar`: + +|--lib +| | +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html +| | +| |--Foo +| | |- Foo.c +| | |- Foo.h +| | +| |- README --> THIS FILE +| +|- platformio.ini +|--src + |- main.c + +and a contents of `src/main.c`: +``` +#include +#include + +int main (void) +{ + ... +} + +``` + +PlatformIO Library Dependency Finder will find automatically dependent +libraries scanning project source files. + +More information about PlatformIO Library Dependency Finder +- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/code/radar_speed_sign/platformio.ini b/code/radar_speed_sign/platformio.ini index 45cd6f5..1e68244 100644 --- a/code/radar_speed_sign/platformio.ini +++ b/code/radar_speed_sign/platformio.ini @@ -1,19 +1,19 @@ -; PlatformIO Project Configuration File -; -; Build options: build flags, source filter -; Upload options: custom upload port, speed and extra flags -; Library options: dependencies, extra library storages -; Advanced options: extra scripting -; -; Please visit documentation for the other options and examples -; https://docs.platformio.org/page/projectconf.html - -[env:nanoatmega328] -platform = atmelavr -board = nanoatmega328new -framework = arduino -upload_port = /dev/cu.wchusbserial1410 -lib_deps = - marcoschwartz/LiquidCrystal_I2C@^1.1.4 - soligen2010/ClickEncoder@0.0.0-alpha+sha.9337a0c46c - paulstoffregen/TimerOne@^1.1 +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html + +[env:nanoatmega328] +platform = atmelavr +board = nanoatmega328new +framework = arduino +upload_port = /dev/cu.wchusbserial1410 +lib_deps = + marcoschwartz/LiquidCrystal_I2C@^1.1.4 + soligen2010/ClickEncoder@0.0.0-alpha+sha.9337a0c46c + paulstoffregen/TimerOne@^1.1 diff --git a/code/radar_speed_sign/src/hb100.cpp b/code/radar_speed_sign/src/hb100.cpp index 43d9630..e3c6a18 100644 --- a/code/radar_speed_sign/src/hb100.cpp +++ b/code/radar_speed_sign/src/hb100.cpp @@ -1,20 +1,20 @@ -#include "hb100.hh" - -uint16_t HB100::calc_speed() { - uint16_t curr_speed = 31360 / last_pulse_period; // V = Fd / 31.36, Fd = 1 / last_pulse_period[s] - _speed_buf[_speed_buf_index] = curr_speed; - _speed_buf_index++; - if (_speed_buf_index >= SPEED_BUF_SIZE) { - _speed_buf_index = 0; // wrap - } - uint32_t averaged_speed = 0; - uint16_t max_speed = 0; - for (size_t i = 0; i < SPEED_BUF_SIZE; i++) { - averaged_speed += _speed_buf[i]; - if (_speed_buf[i] > max_speed) { - max_speed = _speed_buf[i]; - } - } - // return (uint16_t)(averaged_speed / SPEED_BUF_SIZE); - return max_speed; +#include "hb100.hh" + +uint16_t HB100::calc_speed() { + uint16_t curr_speed = 31360 / last_pulse_period; // V = Fd / 31.36, Fd = 1 / last_pulse_period[s] + _speed_buf[_speed_buf_index] = curr_speed; + _speed_buf_index++; + if (_speed_buf_index >= SPEED_BUF_SIZE) { + _speed_buf_index = 0; // wrap + } + uint32_t averaged_speed = 0; + uint16_t max_speed = 0; + for (size_t i = 0; i < SPEED_BUF_SIZE; i++) { + averaged_speed += _speed_buf[i]; + if (_speed_buf[i] > max_speed) { + max_speed = _speed_buf[i]; + } + } + // return (uint16_t)(averaged_speed / SPEED_BUF_SIZE); + return max_speed; } \ No newline at end of file diff --git a/code/radar_speed_sign/src/main.cpp b/code/radar_speed_sign/src/main.cpp index e2a27fb..508602a 100644 --- a/code/radar_speed_sign/src/main.cpp +++ b/code/radar_speed_sign/src/main.cpp @@ -1,86 +1,86 @@ -#include -#include -#include -#include -#include -#include -#include - -#include "seven_seg.hh" -#include "hb100.hh" - -#define RADAR_PIN 2 - -#define LCD_ADDRESS 0x27 -#define LCD_WIDTH_CHARS 16 -#define LCD_HEIGHT_LINES 2 - -#define ENCODER_PIN_A A1 -#define ENCODER_PIN_B A0 -#define ENCODER_PIN_BTN A2 -#define ENCODER_STEPS_PER_NOTCH 1 - - -volatile uint32_t last_pulse_us = micros(); // [ms] time of last radar pulse -volatile uint32_t last_pulse_period = 0; // [ms] time between last two falling edges from radar - -LiquidCrystal_I2C lcd(LCD_ADDRESS, LCD_WIDTH_CHARS, LCD_HEIGHT_LINES); -ClickEncoder* encoder; - -SevenSeg seven_seg; // 7-segment display -HB100 hb100; // radar - -void timer1_isr() { - encoder->service(); -} - -/** - * Interrupt handler that triggers on falling pulses from HB100 radar - **/ -void radar_isr() { - hb100.last_pulse_period = micros() - hb100.last_pulse_us; - hb100.last_pulse_us = micros(); -} - -void setup() { - Serial.begin(9600); - - // Initialize radar. - pinMode(RADAR_PIN, INPUT); - attachInterrupt(digitalPinToInterrupt(RADAR_PIN), radar_isr, FALLING); - - // Initialize 7-segment display. - seven_seg.init(); - - // Initialize LCD. - lcd.init(); // initialize the lcd - lcd.backlight(); - lcd.setCursor(0,0); - lcd.clear(); - - // Initialize encoder. - encoder = new ClickEncoder(ENCODER_PIN_A, ENCODER_PIN_B, ENCODER_PIN_BTN, ENCODER_STEPS_PER_NOTCH); - Timer1.initialize(500); - Timer1.attachInterrupt(timer1_isr); -} - -void loop() { - // put your main code here, to run repeatedly: - uint16_t transfer_value = 0; - while (true) { - transfer_value = hb100.calc_speed(); - // Serial.print("HB100 last pulse period: "); - // Serial.println(hb100.last_pulse_period); - // Serial.print("Calculated speed: "); - Serial.print(hb100.last_pulse_period); - Serial.print(" "); - Serial.println(hb100.calc_speed()); - seven_seg.write(hb100.calc_speed()); - delay(10); - // transfer_value++; - // if (transfer_value > 99) { - // transfer_value = 0; - // } - } -} - +#include +#include +#include +#include +#include +#include +#include + +#include "seven_seg.hh" +#include "hb100.hh" + +#define RADAR_PIN 2 + +#define LCD_ADDRESS 0x27 +#define LCD_WIDTH_CHARS 16 +#define LCD_HEIGHT_LINES 2 + +#define ENCODER_PIN_A A1 +#define ENCODER_PIN_B A0 +#define ENCODER_PIN_BTN A2 +#define ENCODER_STEPS_PER_NOTCH 1 + + +volatile uint32_t last_pulse_us = micros(); // [ms] time of last radar pulse +volatile uint32_t last_pulse_period = 0; // [ms] time between last two falling edges from radar + +LiquidCrystal_I2C lcd(LCD_ADDRESS, LCD_WIDTH_CHARS, LCD_HEIGHT_LINES); +ClickEncoder* encoder; + +SevenSeg seven_seg; // 7-segment display +HB100 hb100; // radar + +void timer1_isr() { + encoder->service(); +} + +/** + * Interrupt handler that triggers on falling pulses from HB100 radar + **/ +void radar_isr() { + hb100.last_pulse_period = micros() - hb100.last_pulse_us; + hb100.last_pulse_us = micros(); +} + +void setup() { + Serial.begin(9600); + + // Initialize radar. + pinMode(RADAR_PIN, INPUT); + attachInterrupt(digitalPinToInterrupt(RADAR_PIN), radar_isr, FALLING); + + // Initialize 7-segment display. + seven_seg.init(); + + // Initialize LCD. + lcd.init(); // initialize the lcd + lcd.backlight(); + lcd.setCursor(0,0); + lcd.clear(); + + // Initialize encoder. + encoder = new ClickEncoder(ENCODER_PIN_A, ENCODER_PIN_B, ENCODER_PIN_BTN, ENCODER_STEPS_PER_NOTCH); + Timer1.initialize(500); + Timer1.attachInterrupt(timer1_isr); +} + +void loop() { + // put your main code here, to run repeatedly: + uint16_t transfer_value = 0; + while (true) { + transfer_value = hb100.calc_speed(); + // Serial.print("HB100 last pulse period: "); + // Serial.println(hb100.last_pulse_period); + // Serial.print("Calculated speed: "); + Serial.print(hb100.last_pulse_period); + Serial.print(" "); + Serial.println(hb100.calc_speed()); + seven_seg.write(hb100.calc_speed()); + delay(10); + // transfer_value++; + // if (transfer_value > 99) { + // transfer_value = 0; + // } + } +} + diff --git a/code/radar_speed_sign/src/seven_seg.cpp b/code/radar_speed_sign/src/seven_seg.cpp index c005308..1677cf3 100644 --- a/code/radar_speed_sign/src/seven_seg.cpp +++ b/code/radar_speed_sign/src/seven_seg.cpp @@ -1,79 +1,79 @@ -#include "seven_seg.hh" - -void SevenSeg::init() { - // Initialize 7-segment Display. - pinMode(_spi_rclk_pin, OUTPUT); - SPI.begin(); -} - -/** - * Converts a single digit value to a segment map. - * - * @param digit Digit value. - * @retval Segment map. - **/ -uint8_t SevenSeg::digit_to_seg(uint8_t digit, bool decimal=false) { - // Serial.print("\tdigit: "); - // Serial.println(digit); - uint8_t seg_map = SEVEN_SEG_F; - switch (digit) { - case 0: - seg_map = SEVEN_SEG_0; - break; - case 1: - seg_map = SEVEN_SEG_1; - break; - case 2: - seg_map = SEVEN_SEG_2; - break; - case 3: - seg_map = SEVEN_SEG_3; - break; - case 4: - seg_map =SEVEN_SEG_4; - break; - case 5: - seg_map = SEVEN_SEG_5; - break; - case 6: - seg_map = SEVEN_SEG_6; - break; - case 7: - seg_map = SEVEN_SEG_7; - break; - case 8: - seg_map = SEVEN_SEG_8; - break; - case 9: - seg_map = SEVEN_SEG_9; - break; - } - return decimal ? seg_map & ~(1<<7) : seg_map; -} - -void SevenSeg::write(uint8_t value, bool decimal=false) { - uint8_t ones_value = value % 10; - uint8_t tens_value = value / 10; - uint8_t ones_digit; - uint8_t tens_digit; - - if (ones_value == 0 && tens_value == 0) { - // save power when speed is zero - ones_digit = SEVEN_SEG_BLANK; - tens_digit = SEVEN_SEG_BLANK; - } else { - ones_digit = digit_to_seg(ones_value); - // don't display leading zero - tens_digit = tens_value == 0 ? SEVEN_SEG_BLANK : digit_to_seg(tens_value); - } - - uint16_t seg_map = (ones_digit << 8) | tens_digit; - String map_str = String(seg_map, BIN); - - digitalWrite(_spi_rclk_pin, LOW); - SPI.transfer16(seg_map); - digitalWrite(_spi_rclk_pin, HIGH); - // strobe RCLK to transfer registers onto output - - +#include "seven_seg.hh" + +void SevenSeg::init() { + // Initialize 7-segment Display. + pinMode(_spi_rclk_pin, OUTPUT); + SPI.begin(); +} + +/** + * Converts a single digit value to a segment map. + * + * @param digit Digit value. + * @retval Segment map. + **/ +uint8_t SevenSeg::digit_to_seg(uint8_t digit, bool decimal=false) { + // Serial.print("\tdigit: "); + // Serial.println(digit); + uint8_t seg_map = SEVEN_SEG_F; + switch (digit) { + case 0: + seg_map = SEVEN_SEG_0; + break; + case 1: + seg_map = SEVEN_SEG_1; + break; + case 2: + seg_map = SEVEN_SEG_2; + break; + case 3: + seg_map = SEVEN_SEG_3; + break; + case 4: + seg_map =SEVEN_SEG_4; + break; + case 5: + seg_map = SEVEN_SEG_5; + break; + case 6: + seg_map = SEVEN_SEG_6; + break; + case 7: + seg_map = SEVEN_SEG_7; + break; + case 8: + seg_map = SEVEN_SEG_8; + break; + case 9: + seg_map = SEVEN_SEG_9; + break; + } + return decimal ? seg_map & ~(1<<7) : seg_map; +} + +void SevenSeg::write(uint8_t value, bool decimal=false) { + uint8_t ones_value = value % 10; + uint8_t tens_value = value / 10; + uint8_t ones_digit; + uint8_t tens_digit; + + if (ones_value == 0 && tens_value == 0) { + // save power when speed is zero + ones_digit = SEVEN_SEG_BLANK; + tens_digit = SEVEN_SEG_BLANK; + } else { + ones_digit = digit_to_seg(ones_value); + // don't display leading zero + tens_digit = tens_value == 0 ? SEVEN_SEG_BLANK : digit_to_seg(tens_value); + } + + uint16_t seg_map = (ones_digit << 8) | tens_digit; + String map_str = String(seg_map, BIN); + + digitalWrite(_spi_rclk_pin, LOW); + SPI.transfer16(seg_map); + digitalWrite(_spi_rclk_pin, HIGH); + // strobe RCLK to transfer registers onto output + + } \ No newline at end of file diff --git a/code/radar_speed_sign/test/README b/code/radar_speed_sign/test/README index b94d089..e7d1588 100644 --- a/code/radar_speed_sign/test/README +++ b/code/radar_speed_sign/test/README @@ -1,11 +1,11 @@ - -This directory is intended for PlatformIO Unit Testing and project tests. - -Unit Testing is a software testing method by which individual units of -source code, sets of one or more MCU program modules together with associated -control data, usage procedures, and operating procedures, are tested to -determine whether they are fit for use. Unit testing finds problems early -in the development cycle. - -More information about PlatformIO Unit Testing: -- https://docs.platformio.org/page/plus/unit-testing.html + +This directory is intended for PlatformIO Unit Testing and project tests. + +Unit Testing is a software testing method by which individual units of +source code, sets of one or more MCU program modules together with associated +control data, usage procedures, and operating procedures, are tested to +determine whether they are fit for use. Unit testing finds problems early +in the development cycle. + +More information about PlatformIO Unit Testing: +- https://docs.platformio.org/page/plus/unit-testing.html diff --git a/datasheets/HB100_Microwave_Sensor_Application_Note.pdf b/datasheets/HB100_Microwave_Sensor_Application_Note.pdf new file mode 100644 index 0000000..49721c2 Binary files /dev/null and b/datasheets/HB100_Microwave_Sensor_Application_Note.pdf differ