first commit

This commit is contained in:
Guillaume BONABAU 2025-04-24 08:16:16 +02:00
commit 8849345bc3
285 changed files with 543 additions and 0 deletions

5
.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

10
.vscode/extensions.json vendored Normal file
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"
]
}

5
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,5 @@
{
"files.associations": {
"random": "cpp"
}
}

37
include/README Normal file
View File

@ -0,0 +1,37 @@
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 convention is to give header files names that end with `.h'.
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
lib/README Normal file
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 the executable file.
The source code of each library should be placed in a separate directory
("lib/your_library_name/[Code]").
For example, see the structure of the following example libraries `Foo` and `Bar`:
|--lib
| |
| |--Bar
| | |--docs
| | |--examples
| | |--src
| | |- Bar.c
| | |- Bar.h
| | |- library.json (optional. for 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
Example contents of `src/main.c` using Foo and Bar:
```
#include <Foo.h>
#include <Bar.h>
int main (void)
{
...
}
```
The PlatformIO Library Dependency Finder will find automatically dependent
libraries by scanning project source files.
More information about PlatformIO Library Dependency Finder
- https://docs.platformio.org/page/librarymanager/ldf.html

16
platformio.ini Normal file
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:upesy_wrover]
platform = espressif32
board = upesy_wrover
framework = arduino
monitor_speed = 115200
monitor_raw = true

86
pysrc/Controller.py Normal file
View File

@ -0,0 +1,86 @@
import serial
import time
import pygame
from pydub import AudioSegment
import serial.tools.list_ports
# Define the paths
#Short notes
NOTES_PATH = "Player\\notes\\mp3-master\\"
#Long notes
#NOTES_PATH = r"C:\Users\Balthazar\Shared\ECAM\Advance Robotique\Project\Player\notes\high-quality-master\renamed\\"
SERIAL_PORT = "COM5"
BAUD_RATE = 115200
# New Features
wait_note_finish = False
keyboard_input = False
check_com3 = True
pygame.mixer.init()
notes = ["C", "Db", "D", "Eb", "E", "F", "Gb", "G", "Ab", "A", "Bb", "B"]
def play_note_with_pygame(note):
try:
pygame_sound = pygame.mixer.Sound(f"{NOTES_PATH}{note}.mp3")
pygame_sound.play()
if wait_note_finish:
while pygame.mixer.get_busy():
pygame.time.Clock().tick(10)
except Exception as e:
print(f"Error playing {note}: {e}")
# Check if COM port is connected
if check_com3:
ports = list(serial.tools.list_ports.comports())
com3_found = any(port.device == SERIAL_PORT for port in ports)
if not com3_found:
print(f"{SERIAL_PORT} not found. Switching to keyboard input mode.")
keyboard_input = True
try:
ser = serial.Serial(SERIAL_PORT, BAUD_RATE, timeout=1)
time.sleep(2)
except Exception as e:
print(f"Error opening {SERIAL_PORT}: {e}")
keyboard_input = True
print("Listening for Arduino input...")
while True:
try:
# Keyboard input fallback
if keyboard_input:
user_input = input("Enter octave; note (e.g., 4; C) or 'q' to quit: ")
if user_input == 'q':
break
try:
octave_str, note_part = user_input.split(";")
octave = int(octave_str.strip())
note = note_part.strip().split()[0] # Get only the first note
if note in notes:
play_note_with_pygame(f"{note}{octave}")
except:
print("Invalid input format.")
# Arduino input
data = ser.readline().decode('utf-8', errors='ignore').strip()
if data:
print("data: " + data)
try:
octave_str, note_part = data.split(";")
octave = int(octave_str.strip())
note = note_part.strip().split()[0] # Only one note expected
if note in notes:
play_note_with_pygame(f"{note}{octave}")
except Exception as e:
print(f"Invalid format or error parsing data: {e}")
except KeyboardInterrupt:
print("Exiting...")
break
except Exception as e:
print(f"Error: {e}")
ser.close()

80
pysrc/ControllerV1.py Normal file
View File

@ -0,0 +1,80 @@
import serial
import time
import pygame
from pydub import AudioSegment
import serial.tools.list_ports
# Define the paths
#Short notes
NOTES_PATH = "Player\\notes\\mp3-master\\"
#Long notes
#NOTES_PATH = r"C:\Users\Balthazar\Shared\ECAM\Advance Robotique\Project\Player\notes\high-quality-master\renamed\\"
SERIAL_PORT = "COM5" #"COM3"
BAUD_RATE = 115200
# New Features
wait_note_finish = False # Set to False to play without waiting for the note to finish
keyboard_input = False # Set to False to disable keyboard note input
check_com3 = True # Set to False to skip COM3 check
pygame.mixer.init()
octave = 4
notes = ["C", "Db", "D", "Eb", "E", "F", "Gb", "G", "Ab", "A", "Bb", "B"]
def play_note_with_pygame(note):
try:
pygame_sound = pygame.mixer.Sound(f"{NOTES_PATH}{note}.mp3")
pygame_sound.play()
if wait_note_finish:
while pygame.mixer.get_busy(): # Wait until sound is finished
pygame.time.Clock().tick(10)
except Exception as e:
print(f"Error playing {note}: {e}")
# Check if COM3 is connected
if check_com3:
ports = list(serial.tools.list_ports.comports())
com3_found = any(port.device == SERIAL_PORT for port in ports)
if not com3_found:
print(f"{SERIAL_PORT} not found. Switching to keyboard input mode.")
keyboard_input = True
try:
ser = serial.Serial(SERIAL_PORT, BAUD_RATE, timeout=1)
time.sleep(2)
except Exception as e:
print(f"Error opening {SERIAL_PORT}: {e}")
keyboard_input = True
print("Listening for Arduino input...")
while True:
try:
# Keyboard input for playing notes
if keyboard_input:
user_input = input("Enter note (C, Db, D, ... B) or 'q' to quit: ")
if user_input == 'q':
break
if user_input in notes:
play_note_with_pygame(f"{user_input}{octave}")
# Arduino input for playing notes
data = ser.readline().decode('utf-8', errors='ignore').strip()
if data:
print("data : " + data)
note = data
if note in notes:
play_note_with_pygame(f"{note}{octave}")
except KeyboardInterrupt:
print("Exiting...")
break
except Exception as e:
print(f"Error: {e}")
ser.close()

BIN
pysrc/notes/Do.wav Normal file

Binary file not shown.

BIN
pysrc/notes/Fa.wav Normal file

Binary file not shown.

BIN
pysrc/notes/La.wav Normal file

Binary file not shown.

BIN
pysrc/notes/Mi.wav Normal file

Binary file not shown.

BIN
pysrc/notes/Re.wav Normal file

Binary file not shown.

BIN
pysrc/notes/Si.wav Normal file

Binary file not shown.

BIN
pysrc/notes/Sol.wav Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Some files were not shown because too many files have changed in this diff Show More