1#include <LiquidCrystal.h>
2#include <Fuzzy.h>
3#include <FuzzyInput.h>
4#include <FuzzySet.h>
5
6
7LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
8
9
10Fuzzy* fuzzy = new Fuzzy();
11FuzzySet* cold = new FuzzySet(0,1,2,3);
12FuzzySet* good = new FuzzySet( 8,9,10, 11);
13FuzzySet* hot = new FuzzySet(13,14,15,16);
14
15
16int x =3;
17int consigne=0;
18
19void setup() {
20
21Serial.begin(9600);
22
23lcd.begin(16, 2);
24
25
26 FuzzyInput* temperature = new FuzzyInput(3);
27 temperature->addFuzzySet(cold);
28 temperature->addFuzzySet(good);
29 temperature->addFuzzySet(hot);
30
31 fuzzy->addFuzzyInput(temperature);
32
33lcd.print("temperature:");
34pinMode(3,OUTPUT);
35pinMode(13,INPUT);
36}
37
38void loop() {
39boolean K1;
40int y,l,z;
41fuzzy->setInput(3, 0);
42
43 y=analogRead(A1);
44 delay(50);
45 z=analogRead(A1);
46 delay(50);
47 l=temp(x,y);
48 z=temp(x,z);
49
50
51
52
53 l=0.4*l+0.6*z;
54 int c;
55 c = analogRead(A0);
56 Serial.println(c);
57 K1=semaphore(digitalRead(13));
58
59 consigne = consigne_param(209,412,K1);
60
61 Serial.print("Temperature: ");
62 Serial.print(cold->getPertinence());
63 Serial.print(", ");
64 Serial.print(good->getPertinence());
65 Serial.print(", ");
66 Serial.println(hot->getPertinence());
67
68 lcd.setCursor(12, 0);
69 lcd.print(l);
70 lcd.setCursor(0,1);
71 lcd.print("consigne:");
72 lcd.setCursor(9,1);
73 lcd.print(consigne);
74
75}
76
77int temp (int coef,int lect)
78{
79 int t;
80 t=lect/coef;
81 return(t);
82}
83
84 int consigne_param(int up, int down, boolean semaph)
85 {
86 int c1;
87 c1 = analogRead(A0);
88 if (semaph)
89 {
90 if ((c1==up) && (consigne<16))
91 consigne = consigne + 1;
92
93 if ((c1==down) && (consigne>0))
94 consigne = consigne - 1 ;
95 }
96 delay(100);
97 return (consigne);
98 }
99
100 boolean semaphore(boolean mode )
101 {
102 return (not mode);
103 }
104
Anonymous user
2 years ago
nice project sister