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;
void setup() {
Serial.begin(9600);
pinMode(s0, OUTPUT);
pinMode(s1, OUTPUT);
pinMode(s2, OUTPUT);
pinMode(s3, OUTPUT);
}
void loop()
{
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);
}
void F0()
{
Serial.print("F0= ");
Serial.println(analogRead(A0));
digitalWrite(s3,LOW);
digitalWrite(s2,LOW);
digitalWrite(s1,LOW);
digitalWrite(s0,LOW);
}
void F1()
{
Serial.print("F1= ");
Serial.println(analogRead(A0));
digitalWrite(s3,LOW);
digitalWrite(s2,LOW);
digitalWrite(s1,LOW);
digitalWrite(s0,HIGH);
}
void F2()
{
Serial.print("F2= ");
Serial.println(analogRead(A0));
digitalWrite(s3,LOW);
digitalWrite(s2,LOW);
digitalWrite(s1,HIGH);
digitalWrite(s0,LOW);
}
void F3()
{
Serial.print("F3= ");
Serial.println(analogRead(A0));
digitalWrite(s3,LOW);
digitalWrite(s2,LOW);
digitalWrite(s1,HIGH);
digitalWrite(s0,HIGH );
}
void F4()
{
digitalWrite(s3,LOW);
digitalWrite(s2,HIGH);
digitalWrite(s1,LOW);
digitalWrite(s0,LOW);
Serial.print("F4= ");
Serial.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;
Serial.print("Temperature 1: ");
Serial.print(celsius);
Serial.println(" ℃");
}
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;
Serial.print("Temperature 2: ");
Serial.print(celsius);
Serial.println(" ℃");
}
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));
Serial.print( "LUX = ");
Serial.println(lux);
}
Loading
cd74hc4067
cd74hc4067