#include <LiquidCrystal.h>
#include <Fuzzy.h>
#include <FuzzyInput.h>
#include <FuzzySet.h>
// select the pins used on the LCD panel
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
// Instantiating an object library
Fuzzy* fuzzy = new Fuzzy();
FuzzySet* cold = new FuzzySet(0,1,2,3);
FuzzySet* good = new FuzzySet( 8,9,10, 11);
FuzzySet* hot = new FuzzySet(13,14,15,16);
//variable declaration
int x =3;
int consigne=0;
void setup() {
//initialize serial communication at 9600 bps:
Serial.begin(9600);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// FuzzyInput
FuzzyInput* temperature = new FuzzyInput(3);
temperature->addFuzzySet(cold);
temperature->addFuzzySet(good);
temperature->addFuzzySet(hot);
fuzzy->addFuzzyInput(temperature);
lcd.print("temperature:");
pinMode(3,OUTPUT);
pinMode(13,INPUT);
}
void loop() {
boolean K1;
int y,l,z;
fuzzy->setInput(3, 0);
y=analogRead(A1);
delay(50);
z=analogRead(A1);
delay(50);
l=temp(x,y);
z=temp(x,z);
// Serial.println(l);
// Serial.println(z);
l=0.4*l+0.6*z;
int c;
c = analogRead(A0);
Serial.println(c);
K1=semaphore(digitalRead(13));
// Serial.println(K1);
consigne = consigne_param(209,412,K1); // 209 et 412 compatible DF robot keypad
Serial.print("Temperature: ");
Serial.print(cold->getPertinence());
Serial.print(", ");
Serial.print(good->getPertinence());
Serial.print(", ");
Serial.println(hot->getPertinence());
lcd.setCursor(12, 0);
lcd.print(l);
lcd.setCursor(0,1);
lcd.print("consigne:");
lcd.setCursor(9,1);
lcd.print(consigne);
}
//This function is used to set the temperature value
int temp (int coef,int lect)
{
int t;
t=lect/coef;
return(t);
}
//Using the buttons to change 'consigne'
int consigne_param(int up, int down, boolean semaph)
{ //please declare int consigne in the header
int c1;
c1 = analogRead(A0);
if (semaph)
{
if ((c1==up) && (consigne<16))
consigne = consigne + 1;
if ((c1==down) && (consigne>0))
consigne = consigne - 1 ;
}
delay(100);
return (consigne);
}
//Start operating mode
boolean semaphore(boolean mode )
{
return (not mode);
}
Comments
Please log in or sign up to comment.