This repository was archived by the owner on Dec 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3,006 changed files
with
222,553 additions
and
30,205 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
#include <LSM303.h> | ||
#include <Wire.h> | ||
#include <Adafruit_NeoPixel.h> | ||
|
||
//#define debug true | ||
|
||
#define PIN 5 | ||
|
||
//Assign unique ID to the sensor | ||
LSM303 mag; | ||
compass.m_min = (LSM303::vector<int16_t>){-363, -647, -609}; | ||
compass.m_max = (LSM303::vector<int16_t>){+880, +1120, +638}; | ||
|
||
//initiate wheel | ||
Adafruit_NeoPixel strip = Adafruit_NeoPixel(27, PIN, NEO_GRB + NEO_KHZ800); | ||
|
||
// assign pixels to directions | ||
const int[] N = {23, 0, 1}; | ||
const int[] NE = { 2, 3, 4}; | ||
const int[] E = { 5, 6, 7}; | ||
const int[] SE = { 8, 9,10}; | ||
const int[] S = {11,12,13}; | ||
const int[] SW = {14,15,16}; | ||
const int[] W = {17,18,19}; | ||
const int[] NW = {20,21,22}; | ||
|
||
// variable de la valeur initiale de "Nord" | ||
int[] indicators = {23, 0, 1}; | ||
//luminosité | ||
const byte level = 10; | ||
|
||
float heading; | ||
|
||
void setup() { | ||
|
||
strip.begin(); | ||
strip.show(); | ||
|
||
#ifdef debug | ||
Serial.begin(9600); | ||
Serial.println("Magnetometer Test"); | ||
Serial.println(""); | ||
|
||
if(!mag.begin()){ | ||
Serial.println("Ooops, pas de LSM303 détecté ... Vérifiez vos cablages!"); | ||
while(1); | ||
} | ||
#endif | ||
|
||
if(mag.begin()){ | ||
colorWipe(strip.Color(55,0,0),50); | ||
} | ||
} | ||
|
||
void loop() { | ||
|
||
sensors_event_t event; | ||
mag.getEvent(&event); | ||
|
||
const float Pi = 3.14159; | ||
|
||
heading = (atan2(event.magnetic.y, event.magnetic.x) * 180) / Pi; | ||
|
||
if (heading < 0) { | ||
heading = 360 + heading; | ||
} | ||
|
||
#ifdef debug | ||
Serial.print("Compass Heading : "); | ||
Serial.println(heading); | ||
#endif | ||
|
||
setIndicator(); | ||
showIndicator(); | ||
delay(50); | ||
} | ||
|
||
void setIndicator(){ | ||
if ((heading >= 22.5)&&(heading < 112.5)){ // NE et E | ||
if ((heading >= 22.5)&&(heading < 67.5)){ //NE | ||
indicators = NE; | ||
} // end NE | ||
if ((heading >= 67.5)&&(heading < 112.5)){//E | ||
indicators = E; | ||
} // end E | ||
} // end NE et E | ||
if ((heading >= 112.5) && (heading < 202.5)){ // SE et S | ||
if ((heading >= 112.5) && (heading < 157.5)){//SE | ||
indicators = SE; | ||
} // end SW | ||
if ((heading >= 157.5) && (heading < 202.5)){//S | ||
indicators = S; | ||
} // end S | ||
} // end SE et S | ||
if ((heading < 202.5) && (heading > 292.5)){ // SW et W | ||
if ((heading < 202.5) && (heading > 247.5){//SW | ||
indicators = SW; | ||
} // end SW | ||
if ((heading < 247.5) && (heading > 292.5){//W | ||
indicators = W; | ||
} // end W | ||
} // end SW et W | ||
if ((heading >= 292.5) || (heading < 22.5)){ // NW et N | ||
if ((heading >= 292.5) && (heading < 337.5)){//NW | ||
indicators = NW; | ||
} // end NW | ||
if ((heading >= 337.5) || (heading < 22.5)){//N | ||
indicators = N; | ||
} // end N | ||
} // end NW et N | ||
} //end setIndicator() | ||
|
||
|
144 changes: 144 additions & 0 deletions
144
Arduino/fonction-packets-reader/fonction-packets-reader.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
#include <Arduino.h> | ||
#include <Adafruit_NeoPixel.h> | ||
#include <bluefruit.h> | ||
|
||
#define NEOPIXEL_VERSION_STRING "Neopixel v2.0" | ||
|
||
#define MAXCOMPONENTS 4 | ||
uint8_t *pixelBuffer = NULL; | ||
uint8_t width = 0; | ||
uint8_t height = 0; | ||
uint8_t stride; | ||
uint8_t componentsValue; | ||
bool is400Hz; | ||
uint8_t components = 3; // only 3 and 4 are valid values | ||
|
||
Adafruit_NeoPixel neopixel = Adafruit_NeoPixel(); | ||
|
||
// BLE Service | ||
BLEDis bledis; | ||
BLEUart bleuart; | ||
|
||
String direction; | ||
int distance; | ||
|
||
void setup() | ||
{ | ||
Serial.begin(115200); | ||
Serial.println("Adafruit Bluefruit Neopixel Test"); | ||
Serial.println("--------------------------------"); | ||
|
||
Serial.println(); | ||
Serial.println("Please connect using the Bluefruit Connect LE application"); | ||
|
||
// Config Neopixels | ||
neopixel.begin(); | ||
|
||
// Init Bluefruit | ||
Bluefruit.autoConnLed(true); | ||
Bluefruit.begin(); | ||
// Set max power. Accepted values are: -40, -30, -20, -16, -12, -8, -4, 0, 4 | ||
Bluefruit.setTxPower(4); | ||
Bluefruit.setName("Bluefruit52"); | ||
Bluefruit.setConnectCallback(connect_callback); | ||
|
||
// Configure and Start Device Information Service | ||
bledis.setManufacturer("Adafruit Industries"); | ||
bledis.setModel("Bluefruit Feather52"); | ||
bledis.begin(); | ||
|
||
// Configure and start BLE UART service | ||
bleuart.begin(); | ||
|
||
// Set up and start advertising | ||
startAdv(); | ||
} | ||
|
||
void startAdv(void) | ||
{ | ||
// Advertising packet | ||
Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE); | ||
Bluefruit.Advertising.addTxPower(); | ||
|
||
// Include bleuart 128-bit uuid | ||
Bluefruit.Advertising.addService(bleuart); | ||
|
||
// Secondary Scan Response packet (optional) | ||
// Since there is no room for 'Name' in Advertising packet | ||
Bluefruit.ScanResponse.addName(); | ||
|
||
/* Start Advertising | ||
* - Enable auto advertising if disconnected | ||
* - Interval: fast mode = 20 ms, slow mode = 152.5 ms | ||
* - Timeout for fast mode is 30 seconds | ||
* - Start(timeout) with timeout = 0 will advertise forever (until connected) | ||
* | ||
* For recommended advertising interval | ||
* https://developer.apple.com/library/content/qa/qa1931/_index.html | ||
*/ | ||
Bluefruit.Advertising.restartOnDisconnect(true); | ||
Bluefruit.Advertising.setInterval(32, 244); // in unit of 0.625 ms | ||
Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode | ||
Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds | ||
} | ||
|
||
void connect_callback(uint16_t conn_handle) | ||
{ | ||
char central_name[32] = { 0 }; | ||
Bluefruit.Gap.getPeerName(conn_handle, central_name, sizeof(central_name)); | ||
|
||
Serial.print("Connected to "); | ||
Serial.println(central_name); | ||
|
||
Serial.println("Please select the 'Neopixels' tab, click 'Connect' and have fun"); | ||
} | ||
|
||
void loop() { | ||
|
||
if ( Bluefruit.connected() && bleuart.notifyEnabled() ) { | ||
|
||
int command = bleuart.read(); | ||
|
||
switch (command) { | ||
case 'D': { // Set Direction | ||
setDirection(); | ||
break; | ||
} | ||
case 'L': { // Set Distance | ||
setDistance(); | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
|
||
String readData(){ //read sent data | ||
String buffer; | ||
while(bleuart.available()){ | ||
buffer += (char) bleuart.read(); | ||
} | ||
return buffer; | ||
} | ||
|
||
int readDataAsNumber() { | ||
String buffer; | ||
while(bleuart.available()){ | ||
buffer += bleuart.read() - 48; | ||
} | ||
return buffer.toInt(); | ||
} | ||
|
||
void setDirection() { | ||
Serial.print("setDirection : "); | ||
direction = readData(); | ||
Serial.println("Data : " + direction); | ||
} | ||
|
||
void setDistance(){ | ||
Serial.print("setDistance : "); | ||
distance = readData().toInt(); | ||
Serial.println("Data: " + distance ); | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.