1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
| // put your setup code here, to run once:
// Based on: Science Guy 14 youTube tutorial
// http://youtu.be/g0pSfyXOXj8
// int ledPin = 13; // the number of the LED pin
String inputString = "";
char numberString[10];
String outputString = ""; // a string to hold incoming data
boolean stringComplete = false; // whether the string is complete
int buttonState = 0;
int x = 0;
void serialEvent() {
while (Serial.available()) {
// // get the new byte:
char inChar = (char)Serial.read();
// add it to the inputString:
inputString += inChar;
// if the incoming character is a newline, set a flag
// so the main loop can do something about it:
if (inChar == '\n') {
stringComplete = true;
}
}
}
void setup() {
// pinMode(ledPin, OUTPUT); // set LED as output
// digitalWrite(ledPin, LOW); //turn off LED
inputString.reserve(200); // reserve 200 bytes for the inputString:
Serial.begin(9600); // set serial speed //alors quun vide
// signifie nimporte quel argument
pinMode(13, OUTPUT); // on definit la sortie digitale pour la LED.
pinMode(2, INPUT); // on definit le bouton poussoir de reset.
pinMode(3, INPUT); // on definit la commande PWM du pont en H
pinMode(4, INPUT);
}
void loop() {
x = x + 1;
static char COM = 0; // le mot-clé static permet de garder la variable intact
// entre les appels
switch (COM) {
case (0): // FONCTIONNEMENT GRAFCET SANS COMMANDE R2EL
////******************grafcet*//
{
while (Serial.available() == 0)
; // do nothing if nothing sent
if (inputString == "led1on") { // test for command 1 then turn on LED
Serial.println("btn1on");
digitalWrite(13, HIGH); // turn on LED
} else if (inputString ==
"led1off") // test for command 0 then turn off LED
{
Serial.println("btn1off");
digitalWrite(13, LOW);
}
// turn off LED
if (stringComplete) {
stringComplete = false;
inputString = "";
}
//
else // if not one of above command, do nothing
{
;
}
//
break;
//
}
/*************commande par visual basic************/ ///////
//
case (1): // fonctionnement en mode réel
{
static char etat = 0; // le mot-clé static permet de garder la variable
// intact entre les appels
switch (etat) {
case (0): // action pour l'étape 0
digitalWrite(13, LOW);
// LED_ON==false;
if (digitalRead(2) == 1) // etape initial - P0
etat = 1; // activation etape suivant
break;
case (1): // action pour l'étape 1
digitalWrite(13, HIGH);
// LED_OFF==false;
if (digitalRead(3) == 1) // position chariot P1
etat = 0;
break;
default: // Ne devrait jamais arriver, mais on sait jamais.
// digitalWrite(12, low);
digitalWrite(13, LOW);
etat = 0;
break;
}
} break;
}
} |
Partager