1 013
modifications
Modifications
Run 2000
,→Code Photon:
=== Code Photon: ===
Telecharger le code photon entier final: [[:File:photon.ino]]
This #include statement was automatically added by the Particle IDE.
#include <TM1637Display.h>
// This #include statement was automatically added by the Particle IDE.
//#include <TM1637Display.h>
/*
Ping sensor HC-SRO4
+ grove 4-digit display
*/
//#include <TM1637Display.h>
#define CLK 2
#define DIO 3
TM1637Display display(CLK, DIO);
int trigPin = D4;
int opti = D1;
int opti1 = D0;
int echoPin = D5;
float v = 331.5 + (0.6 * 20);
int broche_flex = A0;
int lightInput=A2;
int button1=D6;
int button2=D7;
double button2Value;
void setup()
{
display.setBrightness(0x0d);
Serial.begin(9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(trigPin, OUTPUT);
pinMode(broche_flex, INPUT);
pinMode(opti,INPUT);
pinMode(opti1,INPUT);
pinMode(lightInput,INPUT);
pinMode(button1,INPUT);
pinMode(button2,INPUT);
}
void loop() // <3>
{
double opticalInterupt = digitalRead(opti);
double opticalInterupt2 = digitalRead(opti1);
double lightValue=analogRead(lightInput);
double button1Value=digitalRead(button1);
button2Value=digitalRead(button2);
float d=distanceCM();
float flex_capture = 4095 - analogRead(broche_flex);
//boolean appuyer=false;
display.showNumberDec(d);
display.showNumberDec(flex_capture);//Display the Variable value;
display.showNumberDec(opticalInterupt);
display.showNumberDec(opticalInterupt2);
display.showNumberDec(lightValue);
display.showNumberDec(button1Value);
display.showNumberDec(button2Value);
Serial.println(d);
Serial.println(flex_capture);
Serial.println(opticalInterupt);
Serial.println(opticalInterupt2);
Serial.println(lightValue);
Serial.println(button1Value);
Serial.println(button2Value);
//Display the Variable value;
//wait 100 milliseconds so we don't drive ourselves crazy
delay(100); // ms
envoyerJson(d, flex_capture,opticalInterupt,opticalInterupt2,lightValue,button1Value,button2Value);
}
// float Turnigy()
// {
// digitalWrite(Turnigy,LOW);
// }
float distanceCM(){
// send sound pulse
digitalWrite(trigPin, LOW);
delayMicroseconds(3);
digitalWrite(trigPin, HIGH);
delayMicroseconds(5);
digitalWrite(trigPin, LOW);
// listen for echo Pin
float tUs = pulseIn(echoPin, HIGH); // microseconds
float t = tUs / 1000.0 / 1000.0 / 2; // s
float d = t*v; // m
return d*100; // cm
}
void envoyerJson(float distance, float pression,float o,float o2,float l1,float b1,float b2) {
String json;
//On envoie les données à processing
//json = "{\"controle\":{\"pot1\":";
json = "{\"distance\":";
json = json + String(distance);
json = json + ",\"pression\":";
json = json + String(pression);
json = json + ",\"opticalInterupt\":";
json = json + String(o);
json = json + ",\"opticalInterupt2\":";
json = json + String(o2);
json = json + ",\"lightValue\":";
json = json + String(l1);
json = json + ",\"button1Value\":";
json = json + String(b1);
json = json + ",\"button2Value\":";
json = json + String(b2);
json = json + "}";
Serial.println(json);
}
== '''L'installation finale''' ==