initial version
This commit is contained in:
commit
6fdab94f1b
7 changed files with 375 additions and 0 deletions
5
vscode/megamur_lg/.gitignore
vendored
Normal file
5
vscode/megamur_lg/.gitignore
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
.pio
|
||||
.vscode/.browse.c_cpp.db*
|
||||
.vscode/c_cpp_properties.json
|
||||
.vscode/launch.json
|
||||
.vscode/ipch
|
10
vscode/megamur_lg/.vscode/extensions.json
vendored
Normal file
10
vscode/megamur_lg/.vscode/extensions.json
vendored
Normal file
|
@ -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"
|
||||
]
|
||||
}
|
39
vscode/megamur_lg/include/README
Normal file
39
vscode/megamur_lg/include/README
Normal file
|
@ -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
|
46
vscode/megamur_lg/lib/README
Normal file
46
vscode/megamur_lg/lib/README
Normal file
|
@ -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 <Foo.h>
|
||||
#include <Bar.h>
|
||||
|
||||
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
|
15
vscode/megamur_lg/platformio.ini
Normal file
15
vscode/megamur_lg/platformio.ini
Normal file
|
@ -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
|
249
vscode/megamur_lg/src/main.cpp
Normal file
249
vscode/megamur_lg/src/main.cpp
Normal file
|
@ -0,0 +1,249 @@
|
|||
#include <Arduino.h>
|
||||
#include <Adafruit_NeoPixel.h>
|
||||
#ifdef __AVR__
|
||||
#include <avr/power.h>
|
||||
#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<strip.numPixels(); i++) {
|
||||
strip.setPixelColor(i, c);
|
||||
strip.show();
|
||||
delay(wait);
|
||||
}
|
||||
}
|
||||
|
||||
void rainbow(uint8_t wait) {
|
||||
uint16_t i, j;
|
||||
|
||||
for(j=0; j<256; j++) {
|
||||
for(i=0; i<strip.numPixels(); i++) {
|
||||
strip.setPixelColor(i, Wheel((i+j) & 255));
|
||||
}
|
||||
strip.show();
|
||||
delay(wait);
|
||||
}
|
||||
}
|
||||
|
||||
// Slightly different, this makes the rainbow equally distributed throughout
|
||||
void rainbowCycle(uint8_t wait) {
|
||||
uint16_t i, j;
|
||||
|
||||
for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
|
||||
for(i=0; i< strip.numPixels(); i++) {
|
||||
strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
|
||||
}
|
||||
strip.show();
|
||||
delay(wait);
|
||||
}
|
||||
}
|
||||
|
||||
//Theatre-style crawling lights.
|
||||
void theaterChase(uint32_t c, uint8_t wait) {
|
||||
for (int j=0; j<10; j++) { //do 10 cycles of chasing
|
||||
for (int q=0; q < 3; q++) {
|
||||
for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
|
||||
strip.setPixelColor(i+q, c); //turn every third pixel on
|
||||
}
|
||||
strip.show();
|
||||
|
||||
delay(wait);
|
||||
|
||||
for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
|
||||
strip.setPixelColor(i+q, 0); //turn every third pixel off
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Theatre-style crawling lights with rainbow effect
|
||||
void theaterChaseRainbow(uint8_t wait) {
|
||||
for (int j=0; j < 256; j++) { // cycle all 256 colors in the wheel
|
||||
for (int q=0; q < 3; q++) {
|
||||
for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
|
||||
strip.setPixelColor(i+q, Wheel( (i+j) % 255)); //turn every third pixel on
|
||||
}
|
||||
strip.show();
|
||||
|
||||
delay(wait);
|
||||
|
||||
for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
|
||||
strip.setPixelColor(i+q, 0); //turn every third pixel off
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Input a value 0 to 255 to get a color value.
|
||||
// The colours are a transition r - g - b - back to r.
|
||||
uint32_t Wheel(byte WheelPos) {
|
||||
WheelPos = 255 - WheelPos;
|
||||
if(WheelPos < 85) {
|
||||
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
|
||||
}
|
||||
if(WheelPos < 170) {
|
||||
WheelPos -= 85;
|
||||
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
|
||||
}
|
||||
WheelPos -= 170;
|
||||
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
|
||||
}
|
11
vscode/megamur_lg/test/README
Normal file
11
vscode/megamur_lg/test/README
Normal file
|
@ -0,0 +1,11 @@
|
|||
|
||||
This directory is intended for PlatformIO Test Runner 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/en/latest/advanced/unit-testing/index.html
|
Loading…
Reference in a new issue