int s0=12;
int s1=11;
int s2=7;
int s3=5;
const float BETA = 3950;
const float GAMMA = 0.7;
const float RL10 = 50;
int analogValue;
#include <LiquidCrystal_I2C.h>;
LiquidCrystal_I2C LCD(0x27,16,2);
void setup() {
LCD.init();
LCD.backlight();
LCD.begin(16,2);
Serial.begin(9600);
pinMode(s0, OUTPUT);
pinMode(s1, OUTPUT);
pinMode(s2, OUTPUT);
pinMode(s3, OUTPUT);
}
void loop()
{
LCD.setCursor(0,0);
int select=analogRead(A1);
select=map(select,0,1023,0,7);
switch (select){
case 0:
F0();
break;
case 1:
F1();
break;
case 2:
F2();
break;
case 3:
F3();
break;
case 4:
F4();
break;
case 5:
TEMP1();
break;
case 6:
TEMP2();
break;
case 7:
LED();
break;
}
delay(200);
LCD.clear();
}
void F0()
{
digitalWrite(s3,LOW);
digitalWrite(s2,LOW);
digitalWrite(s1,LOW);
digitalWrite(s0,LOW);
LCD.print("F0= ");
LCD.println(analogRead(A0));
}
void F1()
{
digitalWrite(s3,LOW);
digitalWrite(s2,LOW);
digitalWrite(s1,LOW);
digitalWrite(s0,HIGH);
LCD.print("F1= ");
LCD.println(analogRead(A0));
}
void F2()
{
digitalWrite(s3,LOW);
digitalWrite(s2,LOW);
digitalWrite(s1,HIGH);
digitalWrite(s0,LOW);
LCD.print("F2= ");
LCD.println(analogRead(A0));
}
void F3()
{
digitalWrite(s3,LOW);
digitalWrite(s2,LOW);
digitalWrite(s1,HIGH);
digitalWrite(s0,HIGH );
LCD.print("F3= ");
LCD.println(analogRead(A0));
}
void F4()
{
digitalWrite(s3,LOW);
digitalWrite(s2,HIGH);
digitalWrite(s1,LOW);
digitalWrite(s0,LOW);
LCD.print("F4= ");
LCD.println(analogRead(A0));
}
void TEMP1()
{
digitalWrite(s3,LOW);
digitalWrite(s2,HIGH );
digitalWrite(s1,LOW);
digitalWrite(s0,HIGH);
analogValue = analogRead(A0);
float celsius = 1 / (log(1 / (1023. / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
LCD.print("Temperature 1: ");
LCD.setCursor(0,1);
LCD.print(celsius);
LCD.println(" C");
}
void TEMP2()
{
digitalWrite(s3,LOW);
digitalWrite(s2,HIGH);
digitalWrite(s1,HIGH);
digitalWrite(s0,LOW);
analogValue = analogRead(A0);
float celsius = 1 / (log(1 / (1023. / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
LCD.print("Temperature 2: ");
LCD.setCursor(0,1);
LCD.print(celsius);
LCD.println(" C");
}
void LED()
{
digitalWrite(s3,LOW);
digitalWrite(s2,HIGH);
digitalWrite(s1,HIGH);
digitalWrite(s0,HIGH);
int analogValue = analogRead(A2);
float voltage = analogValue / 1024. * 5;
float resistance = 2000 * voltage / (1 - voltage / 5);
float lux = pow(RL10 * 1e3 * pow(10, GAMMA) / resistance, (1 / GAMMA));
LCD.print( "LUX = ");
LCD.println(lux);
}
Loading
cd74hc4067
cd74hc4067