the all thing is working !

This commit is contained in:
Bachir Soussi Chiadmi 2024-06-20 18:08:27 +02:00
parent fbc4292c0a
commit a9db88e9b6
3 changed files with 160 additions and 58 deletions

34
midi/midi.ino Normal file
View File

@ -0,0 +1,34 @@
#include "MIDIUSB.h"
#define NUM_BUTTONS 7
// https://github.com/arduino/tutorials/blob/master/ArduinoZeroMidi/PitchToNote.h
uint8_t intensity = 127;
void setup(){
}
void loop(){
noteOn(0, 95, intensity);
MidiUSB.flush();
delay(1000);
noteOff(0, 95, 0);
MidiUSB.flush();
delay(1000);
}
void noteOn(byte channel, byte pitch, byte velocity) {
midiEventPacket_t noteOn = {0x09, 0x90 | channel, pitch, velocity};
MidiUSB.sendMIDI(noteOn);
}
void noteOff(byte channel, byte pitch, byte velocity) {
midiEventPacket_t noteOff = {0x08, 0x80 | channel, pitch, velocity};
MidiUSB.sendMIDI(noteOff);
}

View File

@ -1,15 +1,6 @@
#include <fifo.h>
#include <midi_messages.h>
#include <midi_serialization.h>
#include <usbboard.h>
#include <usbconfig.h>
#include <usbdrv.h>
#include <usbmidi.h>
#include <Wire.h>
#include <VL53L0X.h>
#include "MIDIUSB.h"
// IR SENSORS
@ -35,11 +26,9 @@ VL53L0X sensor1;
const int trackCount = 3;
int tracksUp[trackCount];
void sendNote(uint8_t channel, uint8_t note, uint8_t velocity) {
USBMIDI.write((velocity != 0 ? 0x90 : 0x80) | (channel & 0xf));
USBMIDI.write(note & 0x7f);
USBMIDI.write(velocity &0x7f);
}
// https://github.com/arduino/tutorials/blob/master/ArduinoZeroMidi/PitchToNote.h
uint8_t intensity = 127;
void setup() {
@ -47,6 +36,11 @@ void setup() {
Serial.begin(115200);
// Set the maximum speed in steps per second:
// wait until serial port opens for native USB devices
// while (! Serial) {
// delay(1);
// }
// VL53L0X
/*WARNING*/
@ -64,24 +58,42 @@ void setup() {
//Change address of sensor and power up next one
pinMode(XSHUT_pin1, INPUT);
sensor1.init();
// sensor1.init();
sensor1.setTimeout(500);
if (!sensor1.init())
{
Serial.println("Failed to detect and initialize sensor1!");
while (1) {}
}
sensor1.setAddress(Sensor1_newAddress);
delay(10);
pinMode(XSHUT_pin2, INPUT);
sensor2.init();
// sensor2.init();
sensor2.setTimeout(500);
if (!sensor2.init())
{
Serial.println("Failed to detect and initialize sensor2!");
while (1) {}
}
sensor2.setAddress(Sensor2_newAddress);
delay(10);
pinMode(XSHUT_pin3, INPUT);
sensor3.init();
// sensor3.init();
sensor3.setTimeout(500);
if (!sensor3.init())
{
Serial.println("Failed to detect and initialize sensor3!");
while (1) {}
}
sensor3.setAddress(Sensor3_newAddress);
delay(10);
sensor1.setTimeout(0);
sensor2.setTimeout(0);
sensor3.setTimeout(0);
// sensor1.setTimeout(0);
// sensor2.setTimeout(0);
// sensor3.setTimeout(0);
// // if (!sensor.init())
// // {
@ -98,68 +110,78 @@ void setup() {
}
void loop() {
// Serial.println('loop');
// Serial.println("loop");
//Handle USB communication
USBMIDI.poll();
while (USBMIDI.available()) {
// We must read entire available data, so in case we receive incoming
// MIDI data, the host wouldn't get stuck.
u8 b = USBMIDI.read();
}
int state1 = sensor1.readRangeContinuousMillimeters();
// Serial.print("s1 : ");
// Serial.print(state1);
// Serial.print(" | ");
if (state1 > 0 && tracksUp[0] == 0)
Serial.print("s1 : ");
Serial.print(state1);
if ((state1 == 0 || state1 > 50) && tracksUp[0] == 0)
{
sendNote(0, 64, 127);
Serial.print(" ON");
noteOn(0, 84, intensity);
MidiUSB.flush();
tracksUp[0] = 1;
}
else
{
}else{
Serial.print(" OFF");
noteOff(0, 84, 0);
MidiUSB.flush();
tracksUp[0] = 0;
}
Serial.print(" | ");
int state2 = sensor2.readRangeContinuousMillimeters();
// Serial.print("s2 : ");
// Serial.print(state2);
// Serial.print(" | ");
if (state2 > 0 && tracksUp[1] == 0)
{
sendNote(0, 65, 127);
Serial.print("s2 : ");
Serial.print(state2);
if ((state2 == 0 || state2 > 50) && tracksUp[1] == 0){
Serial.print(" ON");
noteOn(0, 86, intensity);
MidiUSB.flush();
tracksUp[1] = 1;
}
else
{
}else{
Serial.print(" OFF");
noteOff(0, 86, 0);
MidiUSB.flush();
tracksUp[1] = 0;
}
Serial.print(" | ");
int state3 = sensor3.readRangeContinuousMillimeters();
// Serial.print("s3 : ");
// Serial.println(state3);
Serial.print("s3 : ");
Serial.print(state3);
// Serial.print(" | ");
if (state3 > 0 && tracksUp[2] == 0)
{
sendNote(0, 66, 127);
if ((state3 == 0 || state3 > 50) && tracksUp[2] == 0){
Serial.print(" ON");
noteOn(0, 88, intensity);
MidiUSB.flush();
tracksUp[2] = 1;
}
else
{
}else{
Serial.print(" OFF");
noteOff(0, 88, 0);
MidiUSB.flush();
tracksUp[2] = 0;
}
Serial.println("");
// if (sensor1.timeoutOccurred()) { Serial.print(" TIMEOUT"); }
// if (sensor2.timeoutOccurred()) { Serial.print(" TIMEOUT"); }
// if (sensor3.timeoutOccurred()) { Serial.print(" TIMEOUT"); }
// Flush the output.
USBMIDI.flush();
}
void noteOn(byte channel, byte pitch, byte velocity) {
midiEventPacket_t noteOn = {0x09, 0x90 | channel, pitch, velocity};
MidiUSB.sendMIDI(noteOn);
}
void noteOff(byte channel, byte pitch, byte velocity) {
midiEventPacket_t noteOff = {0x08, 0x80 | channel, pitch, velocity};
MidiUSB.sendMIDI(noteOff);
}

46
vl53l0x/vl53l0x.ino Normal file
View File

@ -0,0 +1,46 @@
/* This example shows how to use continuous mode to take
range measurements with the VL53L0X. It is based on
vl53l0x_ContinuousRanging_Example.c from the VL53L0X API.
The range readings are in units of mm. */
#include <Wire.h>
#include <VL53L0X.h>
VL53L0X sensor;
void setup()
{
Serial.begin(9600);
// wait until serial port opens for native USB devices
while (! Serial) {
delay(1);
}
Wire.begin();
sensor.setTimeout(500);
if (!sensor.init())
{
Serial.println("Failed to detect and initialize sensor!");
while (1) {}
}
// Start continuous back-to-back mode (take readings as
// fast as possible). To use continuous timed mode
// instead, provide a desired inter-measurement period in
// ms (e.g. sensor.startContinuous(100)).
sensor.startContinuous();
}
void loop()
{
Serial.println("loop");
Serial.println(sensor.readRangeContinuousMillimeters());
// if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }
// Serial.println();
}