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 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
|
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#define relaisrNombre 3
#define ToNombre 3
LiquidCrystal_I2C lcd1(0x27, 16, 2);
LiquidCrystal_I2C lcd2(0x26, 16, 2);
LiquidCrystal_I2C lcd3(0x25, 16, 2);
#define sensorNombre ledNombre *1
//mise en tableau des pin des sensors
const byte sensorPin [] = { 2, 3, 18};
const byte sensorEtatDetect = LOW; // Etat lu d'un sensor detecté
const byte led_Builtin;
#define ledNombre 9
const byte ledPin [] = { 4, 5, 6, 7, 8, 9, 10, 11, 12};
led led[ledNombre]; //création des leds en tableau
int ledDebut = [ledNombre];
const byte relaisPin [] = { 14, 15, 16};
unsigned long To [] = { To1, To2, To3};
volatile int cnt1 = 0;
volatile int cnt2 = 0;
volatile int cnt3 = 0;
volatile int revs1 = 0;
volatile int revs2 = 0;
volatile int revs3 = 0;
const int SpeedLow = 500;
const int SpeedMidle = 1999;
const int SpeedHigh = 2000;
void ISR1_pulse() {
cnt1++;
}
void ISR2_pulse() {
cnt2++;
}
void ISR3_pulse() {
cnt3++;
}
void setup() {
// put your setup code here, to run once:
lcd.println("\Initialisation des Leds");
lcd1.init();
lcd2.init();
lcd3.init();
lcd1.backlight();
lcd2.backlight();
lcd3.backlight();
delay(1000);
lcd1.setCursor(0, 0);
lcd1.print("fadim1");
delay(1000);
lcd1.setCursor(2, 1);
lcd1.print("fourche1");
delay(2000);
lcd1.clear();
lcd2.setCursor(0, 0);
lcd2.print("fadim2");
delay(1000);
lcd2.setCursor(2, 1);
lcd2.print("fourche2");
delay(2000);
lcd2.clear();
lcd3.setCursor(0, 0);
lcd3.print("fadim3");
delay(1000);
lcd3.setCursor(2, 1);
lcd3.print("fourche3");
delay(2000);
lcd3.clear();
for ( int s = 0; s < ledNombre; s ++)
{
led[s].attach(ledPin[s]);
}
//for(int b = 0; b < sensorNombre; b ++){
pinMode(led_Builtin, OUTPUT);
//pinMode(sensor,INPUT);
pinMode(Green_led1, OUTPUT);
pinMode(Red_led1, OUTPUT);
pinMode(relais1, OUTPUT);
pinMode(Green_led2, OUTPUT);
pinMode(Red_led2, OUTPUT);
pinMode(relais2, OUTPUT);
pinMode(Green_led3, OUTPUT);
pinMode(Red_led3, OUTPUT);
pinMode(relais3, OUTPUT);
digitalWrite(led_Builtin, LOW);
attachInterrupt(digitalPinToInterrupt(1), ISR1_pulse, RISING);
attachInterrupt(digitalPinToInterrupt(2), ISR2_pulse, RISING);
attachInterrupt(digitalPinToInterrupt(3), ISR3_pulse, RISING);
}
void loop() {
// put your main code here, to run repeatedly:
unsigned long T1 = millis();
//for (int s = 0; s < ledNombre; s ++){
if ( T1 - To1 >= 2000) {
int c1 = cnt1;
cnt1 = 0;
To1 = T1;
lcd1.setCursor(0, 0);
lcd1.print("Vitesse_moteur1:");
lcd1.setCursor(6, 1);
revs1 = c1 * 30;
lcd1.print(revs1);
lcd1.println("RPM");
digitalWrite(Green_led1, revs1 < SpeedLow1);
digitalWrite(
int isSpeedy1 = (revs1 > SpeedHigh1);
digitalWrite(Red_led1, isSpeedy1);
digitalWrite(relais1, isSpeedy1);
}
}
unsigned long T2 = millis();
if ( T2 - To2 >= 2000) {
int c2 = cnt2;
cnt2 = 0;
To2 = T2;
lcd2.setCursor(0, 0);
lcd2.print("Vitesse_moteur2:");
lcd2.setCursor(6, 1);
revs2 = c2 * 30;
lcd2.print(revs2);
lcd2.println("RPM");
digitalWrite(Green_led2, revs2 > SpeedLow2);
int isSpeedy2 = (revs2 > SpeedHigh2);
digitalWrite(Red_led2, isSpeedy2);
digitalWrite(relais2, isSpeedy2);
}
unsigned long T3 = millis();
if ( T3 - To3 >= 2000) {
int c3 = cnt3;
cnt3 = 0;
To3 = T3;
lcd3.setCursor(0, 0);
lcd3.print("Vitesse_moteur3:");
lcd3.setCursor(6, 1);
revs3 = c3 * 30;
lcd3.print(revs3);
lcd3.println("RPM");
digitalWrite(Green_led3, revs3 > SpeedLow3);
int isSpeedy3 = (revs3 > SpeedHigh3);
digitalWrite(Red_led3, isSpeedy3);
digitalWrite(relais3, isSpeedy3);
}
} |
Partager