Skip to content
This repository was archived by the owner on Dec 1, 2022. It is now read-only.

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
mrquentin committed Apr 4, 2018
1 parent 55116ae commit 719a990
Show file tree
Hide file tree
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.
113 changes: 113 additions & 0 deletions Arduino/bousole/bousole.ino
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 Arduino/fonction-packets-reader/fonction-packets-reader.ino
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 );
}



48 changes: 20 additions & 28 deletions Arduino/packets-reader/packets-reader.ino
Original file line number Diff line number Diff line change
Expand Up @@ -57,37 +57,27 @@ void startAdv(void){
}

void loop() {

while(Serial.available()){ //envoie de donnees
delay(2);
uint8_t buf[64];
int count = Serial.readBytes(buf,sizeof(buf));
Serial.print("TX: ");
for(int i=0; i<count; i++){Serial.print((char)buf[i]);}
Serial.println();
bleuart.write(buf,count);
}

while(bleuart.available()){ //recuperation de donnees
uint8_t ch;
ch = (uint8_t) bleuart.read();
analyseData(ch);
//Serial.write(ch);
if (bleuart.available()){
int command = bleuart.read();
switch(command){
case 'D': {
setDirection();
break;
}
case 'L': {
setDistance();
break;
}
}
}
waitForEvent(); // Request CPU to enter low-power mode until an event/interrupt occurs

}

uint8_t analyseData(uint8_t data){
if(data != 10){
recievedStr = recievedStr + (char)data;
char str [2];
sprintf(str,"%x",data);
recievedHex = recievedHex + str[0] + str[1] + " ";
}else{
Serial.println("RX: " + recievedStr + " (" + recievedHex + ")");
recievedHex, recievedStr = "";
}
void setDirection(){
Serial.printf("setDirection : color(%d, %d, %d)\n", bleuart.read(), bleuart.read(), bleuart.read());

}
void setDistance(){
Serial.println("setDistance");
}

void connect_callback(uint16_t conn_handle){
Expand All @@ -112,3 +102,5 @@ void blink_timer_callback(TimerHandle_t xTimerID)
//digitalToggle(LED_RED);
}



4 changes: 4 additions & 0 deletions Ble_Scan_Connect_App/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ android {
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
sourceSets {
main.java.srcDirs += 'src/main/lib/sweetblue/src'
main.res.srcDirs += 'src/main/lib/sweetblue/res'
}
buildTypes {
release {
minifyEnabled false
Expand Down
3 changes: 2 additions & 1 deletion Ble_Scan_Connect_App/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mrquentin.ble_scan_connect_app">

<uses-feature android:name="android.hardware.bluetooth"/>
<uses-feature android:name="android.hardware.bluetooth_le" android:required="true" />
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.BLUETOOTH_PRIVILEGED"/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.os.Build;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
Expand All @@ -31,7 +32,6 @@ public class MainActivity extends AppCompatActivity implements AdapterView.OnIte

ListView lvNewDevices;


// Create a BroadcastReceiver for ACTION_FOUND
private final BroadcastReceiver mBroadcastReceiver1 = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
Expand Down
Loading

0 comments on commit 719a990

Please sign in to comment.