commit 6fdab94f1b29b8e2d66c93411f49cce9de3d972f Author: jenoack Date: Wed Jul 6 21:27:01 2022 +0200 initial version diff --git a/vscode/megamur_lg/.gitignore b/vscode/megamur_lg/.gitignore new file mode 100644 index 0000000..89cc49c --- /dev/null +++ b/vscode/megamur_lg/.gitignore @@ -0,0 +1,5 @@ +.pio +.vscode/.browse.c_cpp.db* +.vscode/c_cpp_properties.json +.vscode/launch.json +.vscode/ipch diff --git a/vscode/megamur_lg/.vscode/extensions.json b/vscode/megamur_lg/.vscode/extensions.json new file mode 100644 index 0000000..080e70d --- /dev/null +++ b/vscode/megamur_lg/.vscode/extensions.json @@ -0,0 +1,10 @@ +{ + // See http://go.microsoft.com/fwlink/?LinkId=827846 + // for the documentation about the extensions.json format + "recommendations": [ + "platformio.platformio-ide" + ], + "unwantedRecommendations": [ + "ms-vscode.cpptools-extension-pack" + ] +} diff --git a/vscode/megamur_lg/include/README b/vscode/megamur_lg/include/README new file mode 100644 index 0000000..194dcd4 --- /dev/null +++ b/vscode/megamur_lg/include/README @@ -0,0 +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 diff --git a/vscode/megamur_lg/lib/README b/vscode/megamur_lg/lib/README new file mode 100644 index 0000000..6debab1 --- /dev/null +++ b/vscode/megamur_lg/lib/README @@ -0,0 +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 diff --git a/vscode/megamur_lg/platformio.ini b/vscode/megamur_lg/platformio.ini new file mode 100644 index 0000000..fe04ee5 --- /dev/null +++ b/vscode/megamur_lg/platformio.ini @@ -0,0 +1,15 @@ +; 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:megaatmega2560] +platform = atmelavr +board = megaatmega2560 +framework = arduino +lib_deps = adafruit/Adafruit NeoPixel@^1.10.5 diff --git a/vscode/megamur_lg/src/main.cpp b/vscode/megamur_lg/src/main.cpp new file mode 100644 index 0000000..69f4cac --- /dev/null +++ b/vscode/megamur_lg/src/main.cpp @@ -0,0 +1,249 @@ +#include +#include +#ifdef __AVR__ + #include +#endif + +#define MS_TO_WAIT_BEFORE_NEXT_MOVE 1000 //ms to wait before new movement is valid +#define MS_TO_WAIT_BEFORE_VALID_NO_MOVEMEVENT 1000 //ms a no movement phase must be + +#define RGBLEDPIN 4 +#define PIRPIN 5 + +// Parameter 1 = number of pixels in strip +// Parameter 2 = Arduino pin number (most are valid) +// Parameter 3 = pixel type flags, add together as needed: +// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) +// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) +// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) +// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) +// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products) +Adafruit_NeoPixel strip = Adafruit_NeoPixel(366, RGBLEDPIN, NEO_GRB + NEO_KHZ800); + +// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across +// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input +// and minimize distance between Arduino and first pixel. Avoid connecting +// on a live circuit...if you must, connect GND first. + + +void colorWipe(uint32_t c, uint8_t wait); +void rainbow(uint8_t wait) ; +void rainbowCycle(uint8_t wait); +void theaterChase(uint32_t c, uint8_t wait) ; +void theaterChaseRainbow(uint8_t wait) ; +uint32_t Wheel(byte WheelPos); +void check_movement(void); +void led_loop(); + +void setup() { + + Serial.begin(9600); + pinMode(PIRPIN, INPUT); + // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket + #if defined (__AVR_ATtiny85__) + if (F_CPU == 16000000) clock_prescale_set(clock_div_1); + #endif + // End of trinket special code + + strip.begin(); + strip.setBrightness(255); + strip.show(); // Initialize all pixels to 'off' + Serial.println("Starting ..."); +} + +unsigned int led_type_cnt = 0; + +bool movement = false; +bool there_was_no_movement_in_between = true; +bool is_ligthing = false; +unsigned long last_move_ms = 0; +unsigned long last_no_move_ms = 0; + +void loop() { + check_movement(); + led_loop(); +} + +void led_loop() { + + if(false == is_ligthing) + { + if(true == movement) + { + Serial.print("Typcnt="); + led_type_cnt++; + Serial.println(led_type_cnt); + is_ligthing = true; + movement = false; + } + } + + if(true == is_ligthing) + { + + switch(led_type_cnt) + { + case 0: + colorWipe(strip.Color(255, 0, 0), 50); // Red + break; + case 1: + colorWipe(strip.Color(0, 255, 0), 50); // Green + break; + case 2: + colorWipe(strip.Color(0, 0, 255), 50); // Blue + break; + case 3: + theaterChase(strip.Color(127, 127, 127), 50); // White + break; + case 4: + theaterChase(strip.Color(127, 0, 0), 50); // Red + break; + case 5: + theaterChase(strip.Color(0, 0, 127), 50); // Blue + break; + case 6: + rainbow(20); + break; + case 7: + rainbowCycle(20); + break; + case 8: + theaterChaseRainbow(50); + break; + default: + led_type_cnt = 0; + break; + } + } +} + + +void check_movement(void) +{ + int act_movement = digitalRead(PIRPIN); + //if(act_movement == LOW) + // Serial.println("No movement."); + //else + // Serial.println("Movement."); + + if(LOW == act_movement ) + { + if( false == there_was_no_movement_in_between) + { + if(MS_TO_WAIT_BEFORE_VALID_NO_MOVEMEVENT < millis()-last_no_move_ms) + { + there_was_no_movement_in_between = true; + is_ligthing = false; + colorWipe(strip.Color(0, 0, 0), 10); // black + //Serial.println("No movement anymore ..."); + } + } + } + else + { + last_no_move_ms = millis(); + } + + if( true == is_ligthing) + { + last_move_ms = millis(); + } + else + { + if(HIGH == act_movement && true == there_was_no_movement_in_between) + { + there_was_no_movement_in_between = false; + if(MS_TO_WAIT_BEFORE_NEXT_MOVE < millis()-last_move_ms) + { + last_move_ms = millis(); + movement = true; + //Serial.println("New movement detected ..."); + } + } + } +} + +// Fill the dots one after the other with a color +void colorWipe(uint32_t c, uint8_t wait) { + for(uint16_t i=0; i