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 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
| #include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //pin du lcd
int counter = 0; //Variable du coder
int aState; //Variable du coder
int aLastState; //Variable du coder
int relay1=22; //Variable du relais
int relay2=24; //Variable du relais
int relay3=26; //Variable du relais
int relay4=28; //Variable du relais
int relay5=30; //Variable du relais
int relay6=32; //Variable du relais
#define outputA 6
#define outputB 7
void setup() {
pinMode (outputA,INPUT);
pinMode (outputB,INPUT);
pinMode(relay1,OUTPUT);
pinMode(relay2,OUTPUT);
pinMode(relay3,OUTPUT);
pinMode(relay4,OUTPUT);
pinMode(relay5,OUTPUT);
pinMode(relay6,OUTPUT);
Serial.begin (9600);
lcd.begin(16,2);
aLastState = digitalRead(outputA);
}
void loop() {
aState = digitalRead(outputA); // Reads the "current" state of the outputA
// If the previous and the current state of the outputA are different, that means a Pulse has occured
if (aState != aLastState){
// If the outputB state is different to the outputA state, that means the encoder is rotating clockwise
if (digitalRead(outputB) != aState) {
counter ++;
lcd.clear();
} else {
counter --;
lcd.clear();
}
Serial.print("Position: ");
Serial.println(counter);
lcd.setCursor(0, 0);
lcd.print("Position: ");
lcd.setCursor(10, 0);
lcd.print(counter);
}
aLastState = aState; // Updates the previous state of the outputA with the current state
}
if(encoderPosCount==1)
{
lcd.print("moteur avant");
}
{
digitalWrite(relay1,HIGH);
digitalWrite(relay2,LOW);
digitalWrite(relay3,LOW);
digitalWrite(relay4,LOW);
digitalWrite(relay5,LOW);
digitalWrite(relay6,LOW);}
else if (encoderPosCount==2)
{
lcd.print("moteur arriere");
}
{
digitalWrite(relay1,LOW);
digitalWrite(relay2,HIGH);
digitalWrite(relay3,LOW);
digitalWrite(relay4,LOW);
digitalWrite(relay5,LOW);
digitalWrite(relay6,LOW);}
else if (encoderPosCount==3)
{
lcd.print("lampe rouge");
}
{
digitalWrite(relay1,LOW);
digitalWrite(relay2,LOW);
digitalWrite(relay3,HIGH);
digitalWrite(relay4,LOW);
digitalWrite(relay5,LOW);
digitalWrite(relay6,LOW);}
else if (encoderPosCount==4)
{
lcd.print("ventillateur");
}
{
digitalWrite(relay1,LOW);
digitalWrite(relay2,LOW);
digitalWrite(relay3,LOW);
digitalWrite(relay4,HIGH);
digitalWrite(relay5,LOW);
digitalWrite(relay6,LOW);}
else if(encoderPosCount==5)
{
lcd.print("volet 1");
}
{
digitalWrite(relay1,LOW);
digitalWrite(relay2,LOW);
digitalWrite(relay3,LOW);
digitalWrite(relay4,LOW);
digitalWrite(relay5,HIGH);
digitalWrite(relay6,LOW);
}
else if(encoderPosCount==6)
{
lcd.print("volet 2");
}
{
digitalWrite(relay1,LOW);
digitalWrite(relay2,LOW);
digitalWrite(relay3,LOW);
digitalWrite(relay4,LOW);
digitalWrite(relay5,LOW);
digitalWrite(relay6,HIGH);
}
else
{
digitalWrite(relay1,LOW);
digitalWrite(relay2,LOW);
digitalWrite(relay3,LOW);
digitalWrite(relay4,LOW);
digitalWrite(relay5,LOW);
digitalWrite(relay6,LOW);
}
} |
Partager