//#include "HX711.h"
#include <EEPROM.h>
//HX711 scale(A0, A1); // parameter "gain" is ommited; the default value 128 is used by the library
#define key1 11
#define key2 12
#define key3 13
#define relais A2
#define ledbleu A3
#define ledjaune A4
#define ledrouge A5
#define aff1 2
#define aff2 3
#define dp A5
#define AA 4
#define BB 5
#define CC 6
#define DD 7
#define EE 8
#define FF 9
#define GG 10
float pression = 0;
float pmin1 = 1.5, pmin2 = 2;
float pressionmin, pressionmax; // save last values to eeprom
float pressionmineeprom, pressionmaxeeprom; // save last values to eeprom
bool boolpmin = false; // small pressure pmin1 true=>pmin2
float pmax1 = 3.2, pmax2 = 5.2;
bool boolpmax = false; // small pressure pmax1 true=>pmax2
int i = 0;
bool etat = false; // no faillure
unsigned char k1, k2, k3, ilsvalue;
bool kdown1 = false, kdown2 = false, kdown3 = false;
bool validation = false;
int addr = 0;
float lueepromin, lueepromax ;
float sensor_read = 30.5f;
//Prepare binary array for all 7 segment to turn on 7 segment at position of a,b,c,d,e,f,g
//int digit[10] = {0b0111111, 0b0000110, 0b1011011, 0b1001111, 0b1100110, 0b1101101, 0b1111101, 0b0000111, 0b1111111, 0b1101111};
int digit[10] = {0b1000000, 0b1111001, 0b0100100, 0b0110000, 0b0011001, 0b0010010, 0b0000010, 0b1111000, 0b0000000, 0b0010000};
int digit1, digit2; // initialize individual digit to controll each segment
void setup()
{
Serial.begin(9600);
// put your setup code here, to run once:
pinMode(relais, OUTPUT);
pinMode(ledbleu, OUTPUT);
pinMode(ledjaune, OUTPUT);
pinMode(ledrouge, OUTPUT);
pinMode(key1, INPUT_PULLUP);
pinMode(key2, INPUT_PULLUP);
pinMode(key3, INPUT_PULLUP);
//pinMode(ils, INPUT_PULLUP);
pinMode(aff1, OUTPUT);
pinMode(aff2, OUTPUT);
pinMode(dp, OUTPUT);
pinMode(AA, OUTPUT);
pinMode(BB, OUTPUT);
pinMode(CC, OUTPUT);
pinMode(DD, OUTPUT);
pinMode(EE, OUTPUT);
pinMode(FF, OUTPUT);
pinMode(GG, OUTPUT);
//Serial.println(scale.read()); // print a raw reading from the ADC
delay(1000);
//scale.set_scale(0.f); // this value is obtained by calibrating the scale with known weights; see the README for details
//scale.tare();
//save2eeprom (0, pmax1);
EEPROM.get(0, lueepromin);
EEPROM.get(15, lueepromax);
/* digitalWrite(aff1, HIGH);
digitalWrite(aff2, HIGH);*/
}
void loop()
{
for (int j = 0; j <= 99; j++)// for lopp to pass value from 00-99
{
digit2 = j / 10; // unités
digit1 = j % 10; // dizaine
for ( int k = 0; k < 20; k++)// For loop to control the digit control to print 00-99
{
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
dis(digit2);
delay(10);
digitalWrite(3, HIGH);
digitalWrite(2, LOW);
dis(digit1);
delay(10);
}
}
/*ilsvalue = digitalRead(ils); // ok
k1 = digitalRead(key1); // ok (pmin)
k2 = digitalRead(key2); // ok (pmax)
k3 = digitalRead(key3); // ok (validation)
pression = (0.00000133*scale.read()); //-0.49443099;
// -----------------------------------------------------------------
// ------------------- Pressure regulation -----------------------
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
if(k1 ==0)
{ kdown1 =true; delay (5); digitalWrite(ledrouge, LOW);
validation =false;}
if(k1 ==1)
{ if(kdown1== true)
{ kdown1 = false; boolpmin = !boolpmin; delay(10); }}
if(k2 ==0)
{ kdown2 =true; delay (5); digitalWrite(ledrouge, LOW);
validation =false;}
if(k2 ==1)
{ if(kdown2== true)
{ kdown2 = false; boolpmax = !boolpmax; delay(10); }}
if(k3 ==0)
{ kdown3 =true; delay (5); digitalWrite(ledrouge, LOW); }
if(k3 ==1)
{ if(kdown3== true)
{ kdown3 = false; // use the new values and save them to eeprom
pressionmineeprom = pressionmin; pressionmaxeeprom = pressionmax;
validation = true; delay(10); }}
if(boolpmin == true ) { pressionmin = pmin2; }
if(boolpmin == false) { pressionmin = pmin1; }
if(boolpmax == true ) { pressionmax = pmax2; }
if(boolpmax == false) { pressionmax = pmax1; }
if( validation == true)
{
EEPROM.put(0, pressionmin);
EEPROM.put(15, pressionmax);
EEPROM.get(0, lueepromin);
EEPROM.get(15, lueepromax);
validation = false;
}
*/
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// -----------------------------------------------------------------
/*digitalWrite(aff1, LOW);
digitalWrite(aff2, HIGH);
digitalWrite(AA, LOW);
digitalWrite(BB, HIGH);
digitalWrite(CC, HIGH);
digitalWrite(DD, HIGH);
digitalWrite(EE, HIGH);
digitalWrite(FF, HIGH);
digitalWrite(GG, HIGH);
digitalWrite(dp, LOW);
delay(20);
digitalWrite(aff1, HIGH);
digitalWrite(aff2, LOW);
digitalWrite(AA, LOW);
digitalWrite(BB, HIGH);
digitalWrite(CC, LOW);
digitalWrite(DD, HIGH);
digitalWrite(EE, LOW);
digitalWrite(FF, LOW);
digitalWrite(GG, HIGH);
digitalWrite(dp, HIGH);
delay(20);*/
}
void dis(int num)
{
for (int i = 2; i < 9; i++)
{
digitalWrite(i, bitRead(digit[num], i - 2));
}
}
/*#include <EEPROM.h>
#define set 4
#define BTD_up 12
#define BTD_down 13
#define sendd 8
#define BTG_up 6
#define BTG_down 7
#define red 9
#define green 10
#define blue 11
SoftwareSerial HC12(3, 2); // HC-12 TX Pin, HC-12 RX Pin
unsigned int i =0;
unsigned int int_BTD_up, int_BTD_down, int_sendd;
unsigned int int_BTG_down, int_BTG_up;
bool BTD_upTransition, BTD_downTransition;
unsigned char nbbtBTD =0;
bool BTG_upTransition, BTG_downTransition;
unsigned char nbbtBTG =0;
bool BtSendTransition;
unsigned char nbbtBtSend = 0; // true to send
unsigned char roundd = 1;
unsigned long tmpClk =0, tmpLight =0;
unsigned char etat=0;
bool ReadTimerOnes =true;
int16_t positionImageAxeHorizontal = 0; // Position de la gauche de l’image à 20 pixels du bord gauche de l’écran
int16_t positionImageAxeVertical = 0; // Position du haut de l’image à 16 pixels du bord haut de l’écran OLED
int16_t largeurDeLimage = 128; // Largeur de l’image à afficher : 64 pixels
int16_t hauteurDeLimage = 64; // Hauteur de l’image à afficher : 64 pixels
unsigned char both = 0;
unsigned char both_down = 0;
void setup()
{
pinMode( set, OUTPUT);
pinMode( BTD_up, INPUT);
pinMode( BTD_down, INPUT);
pinMode( sendd ,INPUT);
pinMode( BTG_up ,INPUT);
pinMode( BTG_down ,INPUT);
pinMode( red ,OUTPUT);
pinMode( green ,OUTPUT);
pinMode( blue ,OUTPUT);
Serial.begin(9600);
HC12.begin(9600);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(15,10);
display.println("Kar Tech ");
display.setCursor(0,35);
display.setTextSize(1);
display.println("[email protected]");
display.display();
delay(5000);
display.clearDisplay();
display.drawBitmap(positionImageAxeHorizontal, positionImageAxeVertical, imagee, largeurDeLimage, hauteurDeLimage, WHITE);
display.display();
delay(5000);
both =0;
both_down =0;
}
// Reset here =>
void(* ResetFunction) (void) = 0;
void loop()
{
readButtons();
buttonsCounts();
ecran();
delay(20);
*/
//digitalWrite(4, LOW);
/*while (HC12.available()) {
Serial.write(HC12.read()); }
while (Serial.available()) { */
/* i++;
if(i>120){i =48;}
//HC12.write(i);
HC12.println(i);
delay(10); */
//}
//§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§
/*
void buttonsCounts()
{
if(int_BTD_up == 0) { BTD_upTransition =true; }
if(int_BTD_up ==1)
{ if(BTD_upTransition == true) // rising edge
{ BTD_upTransition = false;
nbbtBTD ++;
if(nbbtBTD >99) {nbbtBTD =0; }
delay (10); }}
if(int_BTD_up == 0) { BTD_upTransition =true; } // falling edge
if(int_BTD_up ==1)
{ if(BTD_upTransition == true) // rising edge
{ BTD_upTransition = false;
nbbtBTD ++;
if(nbbtBTD >99) {nbbtBTD =0; }
delay (10); }}
if(int_BTD_down == 0) { BTD_downTransition =true; } // falling edge }
if(int_BTD_down ==1)
{ if(BTD_downTransition == true) // rising edge
{ BTD_downTransition = false;
nbbtBTD --;
if(nbbtBTD >99) {nbbtBTD =0; }
delay (10); }}
if(int_BTG_up == 0) { BTG_upTransition =true; } // falling edge
if(int_BTG_up ==1)
{ if(BTG_upTransition == true) // rising edge
{ BTG_upTransition = false;
nbbtBTG ++;
if(nbbtBTG >99) {nbbtBTG =0; }
delay (10); }}
if(int_BTG_down == 0) { BTG_downTransition =true; } // falling edge }
if(int_BTG_down ==1)
{ if(BTG_downTransition == true) // rising edge
{ BTG_downTransition = false;
nbbtBTG --;
if(nbbtBTG >99) {nbbtBTG =0; }
delay (10); }}
//-------------------------------------------------------------
if(int_sendd ==0) { BtSendTransition =true; } // falling edge
if(int_sendd ==1)
{ if(BtSendTransition == true) // rising edge
{ BtSendTransition = false;
nbbtBtSend ++ ;
delay(10); }}
//-----------------------------------
if(nbbtBtSend==1)
{ if (ReadTimerOnes == true)
{ ReadTimerOnes = false;
tmpClk = millis(); }}
if((millis()-tmpClk)>3000 && nbbtBtSend ==1) // send data
{
display.clearDisplay();
display.setTextSize(2);
display.setCursor(0,25);
display.print("Sending...");
display.display();
delay(3000);
nbbtBtSend =0; ReadTimerOnes = true;}
if((millis()-tmpClk)>3000 && nbbtBtSend ==2) // light leds on
{ tmpLight = millis();
display.clearDisplay();
display.drawBitmap(positionImageAxeHorizontal, positionImageAxeVertical, light, largeurDeLimage, hauteurDeLimage, WHITE);
display.display();
delay(3000);
if(nbbtBTG < nbbtBTD) {rede(); }
if(nbbtBTG > nbbtBTD) {bluee(); }
if(nbbtBTG == nbbtBTD) {greene(); }
nbbtBtSend =0; ReadTimerOnes = true;
}
if((millis()-tmpLight) > 8000) // switch on for 8 seconds
{ ledoff(); }
if(nbbtBtSend > 2)
{
nbbtBtSend =0; }
//------------------------------------------------------
// round ++
//+++++++++++++++++++++++++++++++++++++++
if(int_BTD_up ==0 && int_BTG_up ==0) // add ones execution
{ both = 1; }
if(both ==1)
{ if(int_BTD_up ==0 || int_BTG_up ==0) // no pushed button
{ }
else
{
both=0;
roundd++; nbbtBTD =0;nbbtBTG=0;
if(roundd >3)
{roundd =1;}
}
}
//---------------------------------
// round --
if(int_BTD_down ==0 && int_BTG_down ==0) // add ones execution
{ both_down = 1; }
if(both_down ==1)
{ if(int_BTD_down ==0 || int_BTG_down ==0) // no pushed button
{ }
else
{
both_down=0;
roundd--; nbbtBTD =0;nbbtBTG=0;
if(roundd >1)
{roundd =1;}
}
}
}
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//-------------- colors -------------
void rede()
{RGB_color(255, 0, 0); }
void greene()
{RGB_color(0, 255, 0); }
void bluee()
{RGB_color(0,0,255);}
void magentae()
{ RGB_color(255, 0, 255); }
void yellowe()
{ RGB_color(255, 255, 0); }
void cyane()
{ RGB_color(0, 255, 255); }
void whitee ()
{ RGB_color(254, 254, 254); }
void ledoff ()
{ RGB_color(0, 0, 0); }
void RGB_color(int red_light_value, int green_light_value, int blue_light_value)
{
analogWrite(red, red_light_value);
analogWrite(green, green_light_value);
analogWrite(blue, blue_light_value);
}
//-------------------------------------
void readButtons()
{
int_BTD_up = digitalRead(BTD_up);
int_BTD_down = digitalRead(BTD_down);
int_sendd = digitalRead(sendd);
int_BTG_down = digitalRead(BTG_down);
int_BTG_up = digitalRead(BTG_up);
}
void ecran ()
{
display.clearDisplay();
display.drawFastHLine(0,20,128,1);
display.drawFastHLine(0,21,128,1);
display.drawFastVLine(54,20,128,1);
display.drawFastVLine(53,20,128,1);
display.drawFastVLine(74,20,128,1);
display.drawFastVLine(75,20,128,1);
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(25,0);
display.println("B");
display.setCursor(92,0);
display.println("R");
display.setTextSize(3);
display.setCursor(10,30);
display.println(nbbtBTG);
display.setCursor(86,30);
display.println(nbbtBTD);
display.setCursor(57,0);
display.setTextSize(2);
//display.print(nbbtBtSend);
display.print(roundd);
//display.display();
if(nbbtBtSend ==1)
{
for(int k =56;k<72;k++)
{
display.drawFastVLine(k,42,20,1); // x,y, length
}
}
if(nbbtBtSend ==2)
{
for(int k =56;k<72;k++)
{
display.drawFastVLine(k,20,20,1); // x,y, length
}
}
display.display();
}
*/