Working version with PIR

This commit is contained in:
Jens Noack 2022-05-24 15:53:36 +02:00
parent a926f77fe8
commit 021cc8e73c
10 changed files with 652 additions and 49 deletions

5
vscode/singing_picture_uno/.gitignore vendored Normal file
View file

@ -0,0 +1,5 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch

View 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"
]
}

View 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

View 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

View file

@ -0,0 +1,16 @@
; 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:uno]
platform = atmelavr
board = uno
framework = arduino
monitor_speed = 9600
lib_deps = dfrobot/DFRobotDFPlayerMini@^1.0.5

View file

@ -0,0 +1,272 @@
/***************************************************
Durch Wolfgang Ewald modifizierte Version des FullFunction.ino Beispielsketches der DFRobotDFPlayerMini Bibliothek:
DFPlayer - A Mini MP3 Player For Arduino
<https://www.dfrobot.com/product-1121.html>
***************************************************
This example shows the all the function of library for DFPlayer.
Created 2016-12-07
By [Angelo qiao](Angelo.qiao@dfrobot.com)
GNU Lesser General Public License.
See <http://www.gnu.org/licenses/> for details.
All above must be included in any redistribution
****************************************************/
/***********Notice and Trouble shooting***************
1.Connection and Diagram can be found here
<https://www.dfrobot.com/wiki/index.php/DFPlayer_Mini_SKU:DFR0299#Connection_Diagram>
2.This code is tested on Arduino Uno, Leonardo, Mega boards.
****************************************************/
#include "Arduino.h"
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
SoftwareSerial mySoftwareSerial(10,11); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
void printDetail(uint8_t type, int value);
void readCommand();
void printHelp();
void setup()
{
mySoftwareSerial.begin(9600);
Serial.begin(9600);
Serial.println();
Serial.println(F("DFRobot DFPlayer Mini Demo"));
Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)"));
if (!myDFPlayer.begin(mySoftwareSerial)) { //Use softwareSerial to communicate with mp3.
Serial.println(F("Unable to begin:"));
Serial.println(F("1.Please recheck the connection!"));
Serial.println(F("2.Please insert the SD card!"));
while(true);
}
Serial.println(F("DFPlayer Mini online."));
printHelp();
myDFPlayer.setTimeOut(500); //Set serial communictaion time out 500ms
//----Set volume----
myDFPlayer.volume(10); //Set volume value (0~30).
// myDFPlayer.volumeUp(); //Volume Up
// myDFPlayer.volumeDown(); //Volume Down
//----Set different EQ----
myDFPlayer.EQ(DFPLAYER_EQ_NORMAL);
// myDFPlayer.EQ(DFPLAYER_EQ_POP);
// myDFPlayer.EQ(DFPLAYER_EQ_ROCK);
// myDFPlayer.EQ(DFPLAYER_EQ_JAZZ);
// myDFPlayer.EQ(DFPLAYER_EQ_CLASSIC);
// myDFPlayer.EQ(DFPLAYER_EQ_BASS);
//----Set device we use SD as default----
// myDFPlayer.outputDevice(DFPLAYER_DEVICE_U_DISK);
myDFPlayer.outputDevice(DFPLAYER_DEVICE_SD);
// myDFPlayer.outputDevice(DFPLAYER_DEVICE_AUX);
// myDFPlayer.outputDevice(DFPLAYER_DEVICE_SLEEP);
// myDFPlayer.outputDevice(DFPLAYER_DEVICE_FLASH);
//----Mp3 control----
// myDFPlayer.sleep(); //sleep
// myDFPlayer.reset(); //Reset the module
// myDFPlayer.enableDAC(); //Enable On-chip DAC
// myDFPlayer.disableDAC(); //Disable On-chip DAC
// myDFPlayer.outputSetting(true, 15); //output setting, enable the output and set the gain to 15
}
void loop(){
if(Serial.available()){
readCommand();
}
if (myDFPlayer.available()) {
printDetail(myDFPlayer.readType(), myDFPlayer.read()); //Print the detail message from DFPlayer to handle different errors and states.
}
}
void readCommand(){
char cmd = ' ';
int value1, value2 = 0;
cmd = Serial.read();
value1 = Serial.parseInt();
value2 = Serial.parseInt();
switch(cmd){
case 'h':
printHelp();
break;
case '>':
myDFPlayer.next();
break;
case '<':
myDFPlayer.previous();
break;
case 'p':
if(value2 == 0) myDFPlayer.play(value1);
else if(value1 != 0) myDFPlayer.playFolder(value1, value2);
break;
case 'P':
if(value2 == 0) myDFPlayer.playMp3Folder(value1);
else if(value1 != 0)myDFPlayer.playLargeFolder(value1, value2);
break;
case '+':
myDFPlayer.volumeUp();
break;
case '-':
myDFPlayer.volumeDown();
break;
case 'v':
myDFPlayer.volume(value1);
break;
case 'b':
myDFPlayer.pause();
break;
case 's':
myDFPlayer.start();
break;
case 'z':
myDFPlayer.sleep();
break;
case 'L':
if(value1 == 0) myDFPlayer.enableLoopAll();
else myDFPlayer.loopFolder(value1);
break;
case 'l':
if(value1 == 0) myDFPlayer.disableLoopAll();
else myDFPlayer.loop(value1);
break;
case 'A':
myDFPlayer.advertise(value1);
break;
case 'a':
myDFPlayer.stopAdvertise();
break;
case 'q':
if(value1 == 1) Serial.println(myDFPlayer.readState());
else if(value1 == 2) Serial.println(myDFPlayer.readVolume());
else if(value1 == 3) Serial.println(myDFPlayer.readEQ());
else if(value1 == 4) Serial.println(myDFPlayer.readFileCounts());
else if(value1 == 5) Serial.println(myDFPlayer.readFolderCounts());
else if(value1 == 6) Serial.println(myDFPlayer.readCurrentFileNumber());
break;
default:
Serial.println("Ungültiges Kommando");
break;
}
}
void printHelp(){
Serial.println("DFPlayer Commands:");
Serial.println(" h - help");
Serial.println(" > - next ");
Serial.println(" < - previous");
Serial.println(" p3 - play");
Serial.println(" p3,5 - play folder 3, file 5");
Serial.println(" P3,5 - play large folder 3, file 5");
Serial.println(" P3 - play file 3 in MP3 folder");
Serial.println(" + - volume up");
Serial.println(" - - volume down");
Serial.println(" v10 - set volume to 10");
Serial.println(" b - Pause");
Serial.println(" s - start ");
Serial.println(" z - sleep ");
Serial.println(" L - enable loop all");
Serial.println(" l - disable loop all");
Serial.println(" L3 - loop folder 3");
Serial.println(" l3 - loop file 3");
Serial.println(" A3 - advertise file 3");
Serial.println(" a - stop advertise ");
Serial.println(" qx - query No. x");
Serial.println(" x = 1 - read state");
Serial.println(" x = 2 - read volume");
Serial.println(" x = 3 - read equalizer");
Serial.println(" x = 4 - read file counts");
Serial.println(" x = 5 - read current file number");
Serial.println(" x = 6 - read file counts in folder");
Serial.println(" x = 7 - read folder counts");
}
void printDetail(uint8_t type, int value){
switch (type) {
case TimeOut:
Serial.println(F("Time Out!"));
break;
case WrongStack:
Serial.println(F("Stack Wrong!"));
break;
case DFPlayerCardInserted:
Serial.println(F("Card Inserted!"));
break;
case DFPlayerCardRemoved:
Serial.println(F("Card Removed!"));
break;
case DFPlayerCardOnline:
Serial.println(F("Card Online!"));
break;
case DFPlayerUSBInserted:
Serial.println("USB Inserted!");
break;
case DFPlayerUSBRemoved:
Serial.println("USB Removed!");
break;
case DFPlayerPlayFinished:
Serial.print(F("Number:"));
Serial.print(value);
Serial.println(F(" Play Finished!"));
break;
case DFPlayerError:
Serial.print(F("DFPlayerError:"));
switch (value) {
case Busy:
Serial.println(F("Card not found"));
break;
case Sleeping:
Serial.println(F("Sleeping"));
break;
case SerialWrongStack:
Serial.println(F("Get Wrong Stack"));
break;
case CheckSumNotMatch:
Serial.println(F("Check Sum Not Match"));
break;
case FileIndexOut:
Serial.println(F("File Index Out of Bound"));
break;
case FileMismatch:
Serial.println(F("Cannot Find File"));
break;
case Advertise:
Serial.println(F("In Advertise"));
break;
default:
break;
}
break;
default:
break;
}
}

View file

@ -0,0 +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