Bonjour je passe en projet très bientôt et voilà mon projet presque finis.
int sensorPin = A0;
int s6=6 ;
int s7=7;
int bouton=1;
int sensorvalue = 0;
int boutonstate=0;
void setup() {
pinMode(s6, OUTPUT);
pinMode(s7, OUTPUT);
pinMode (bouton,INPUT);
}
void loop() {
sensorvalue = analogRead(sensorPin);
boutonstate=digitalRead(bouton);
if (boutonstate == HIGH)
{
if (sensorvalue>200 && sensorvalue<250){
digitalWrite(s6, HIGH);
digitalWrite(s7, LOW);
delay(500);
digitalWrite(s6, LOW);
digitalWrite(s7, LOW);
}
if (sensorvalue>250 && sensorvalue<300){
digitalWrite(s6, HIGH);
digitalWrite(s7, LOW);
delay(1000);
digitalWrite(s6, LOW);
digitalWrite(s7, LOW);
}
if (sensorvalue>300 && sensorvalue<350){
digitalWrite(s6, HIGH);
digitalWrite(s7, LOW);
delay(1000);
digitalWrite(s6, LOW);
digitalWrite(s7, LOW);
}
if (sensorvalue>350 && sensorvalue<400){
digitalWrite(s6, HIGH);
digitalWrite(s7, LOW);
delay(1000);
digitalWrite(s6, LOW);
digitalWrite(s7, LOW);
}
if (sensorvalue>400 && sensorvalue<450){
digitalWrite(s6, HIGH);
digitalWrite(s7, LOW);
delay(1000);
digitalWrite(s6, LOW);
digitalWrite(s7, LOW);
}
if (sensorvalue>450 && sensorvalue<500){
digitalWrite(s6, HIGH);
digitalWrite(s7, LOW);
delay(1000);
digitalWrite(s6, LOW);
digitalWrite(s7, LOW);
}
}
}
j'aimerais rajouter le bluetooth dedans mais je ne sais pas trop comment m'y prendre:
j'ai fait l'appli Sur MIT App Inventor, et j'ai fait des boutons avec les intervalles présentes ci dessus, quand je clique sur un bouton d'une intervalle il envoie des chiffres de 1 à 6 selon les intervalles qui feront tourner le moteur.
qui pourrait m'aider à le rédiger sur arduino dans ce programme SVP !!
Mon prof m'a donné ça comme base :
#include <SoftwareSerial.h> //Software Serial Port
#include <Servo.h>
#define RxD 4
#define TxD 5
#define PINLED 13
#define LEDON() digitalWrite(PINLED, HIGH)
#define LEDOFF() digitalWrite(PINLED, LOW)
SoftwareSerial blueToothSerial(RxD,TxD);
int recu;
int pos = 0;
const int broche_servo=9;
Servo myservo;
void setup()
{
Serial.begin(9600);
pinMode(RxD, INPUT);
pinMode(TxD, OUTPUT);
myservo.attach(broche_servo);
pinMode(PINLED, OUTPUT);
LEDOFF();
setupBlueToothConnection();
}
void loop()
{
while(1)
{
if(blueToothSerial.available())
{
recu = blueToothSerial.read();
Serial.print(recu);
if(recu == 2)
{
for(pos = 0; pos < 360; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
}
}
else if(recu == 3)
{
for(pos = 360; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
}
}
else if(recu == 1)
{
LEDON();
}
else if(recu == 0)
{
LEDOFF();
}
}
}
}
void setupBlueToothConnection()
{
blueToothSerial.begin(9600);
blueToothSerial.print("\r\n+STWMOD=0\r\n");
blueToothSerial.print("\r\n+STNA=HMSoft\r\n");
blueToothSerial.print("\r\n+STOAUT=1\r\n");
blueToothSerial.print("\r\n+STAUTO=0\r\n");
delay(2000);
blueToothSerial.print("\r\n+INQ=1\r\n");
Serial.println("The slave bluetooth is inquirable!");
delay(2000);
blueToothSerial.flush();
}
Mais j'ai du mal à les "fusionner".
Donc Voilà j'ai recommencé comme ça:
#include <SoftwareSerial.h>
#define RxD 4
#define TxD 5
#define PinMotorA 10
#define PinMotorB 11
#define DirectionMotorA 12
#define DirectionMotorA 13
#define MotON() digitalWrite(s6, HIGH);
#define MotOFF() digitalWrite(s7, LOW);
SoftwareSerial blueToothSerial(RxD,TxD);
void setup()
{
Serial.begin(9600);
pinMode(RxD, INPUT);
pinMode(TxD, OUTPUT);
pinMode(PinMotorA,OUTPUT);
pinMode(PinMotorB,OUTPUT);
pinMode(DirectionMotorA,OUTPUT);
pinMode(DirectionMotorA,OUTPUT);
}
void loop()
{
while(1)
{
if(blueToothSerial.available())
{recu = blueToothSerial.read();
Serial.print(recu);
if(recu == 1)
{
digitalWrite(s6, HIGH);
digitalWrite(s7, LOW);
delay(3600000);
digitalWrite(s6, LOW);
digitalWrite(s7, LOW);
}
if(recu == 2)
{
digitalWrite(s6, HIGH);
digitalWrite(s7, LOW);
delay(5400000);
digitalWrite(s6, LOW);
digitalWrite(s7, LOW);
}
if(recu == 3)
{
digitalWrite(s6, HIGH);
digitalWrite(s7, LOW);
delay(7200000);
digitalWrite(s6, LOW);
digitalWrite(s7, LOW);
}
if(recu == 4)
{
digitalWrite(s6, HIGH);
digitalWrite(s7, LOW);
delay(9000000);
digitalWrite(s6, LOW);
digitalWrite(s7, LOW);
}
if(recu == 5)
{
digitalWrite(s6, HIGH);
digitalWrite(s7, LOW);
delay(10800000);
digitalWrite(s6, LOW);
digitalWrite(s7, LOW);
}
if(recu == 6)
{
digitalWrite(s6, HIGH);
digitalWrite(s7, LOW);
delay(12600000);
digitalWrite(s6, LOW);
digitalWrite(s7, LOW);
}
}
}
}
void setupBlueToothConnection()
{
blueToothSerial.begin(9600);
blueToothSerial.print("\r\n+STWMOD=0\r\n");
blueToothSerial.print("\r\n+STNA=HMSoft\r\n");
blueToothSerial.print("\r\n+STOAUT=1\r\n");
blueToothSerial.print("\r\n+STAUTO=0\r\n");
delay(2000);
blueToothSerial.print("\r\n+INQ=1\r\n");
Serial.println("The slave bluetooth is inquirable!");
delay(2000);
blueToothSerial.flush();
}
Si vous pouviez m'aider j'en serai Ravi !!
je me suis aussi aidé de :
http://air.imag.fr/index.php/Ardumoto_-_Motor_Driver_Shield
http://mechomaniac.com/ArduinoMotorControlWithTheArdumotoShield
VOilà ce que j'ai fait Sur MIT dans les "Attachement".