Devices & Components
Arduino Uno Rev3
Standard LCD - 16x2 White on Blue
Temperature Sensor
Software & Tools
Arduino IDE
Project description
Code
semaphore and fuzzy function
arduino
Upload this code directly to UNO and make sure you use the wiring similar to mentioned in code
1#include <LiquidCrystal.h> 2#include <Fuzzy.h> 3#include <FuzzyInput.h> 4#include <FuzzySet.h> 5 6// select the pins used on the LCD panel 7LiquidCrystal lcd(8, 9, 4, 5, 6, 7); 8 9// Instantiating an object library 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//variable declaration 16int x =3; 17int consigne=0; 18 19void setup() { 20 //initialize serial communication at 9600 bps: 21Serial.begin(9600); 22// set up the LCD's number of columns and rows: 23lcd.begin(16, 2); 24 25 // FuzzyInput 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 // Serial.println(l); 51 // Serial.println(z); 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 // Serial.println(K1); 59 consigne = consigne_param(209,412,K1); // 209 et 412 compatible DF robot keypad 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//This function is used to set the temperature value 77int temp (int coef,int lect) 78{ 79 int t; 80 t=lect/coef; 81 return(t); 82} 83//Using the buttons to change 'consigne' 84 int consigne_param(int up, int down, boolean semaph) 85 { //please declare int consigne in the header 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 //Start operating mode 100 boolean semaphore(boolean mode ) 101 { 102 return (not mode); 103 } 104
Comments
Only logged in users can leave comments