Skip to content

Instantly share code, notes, and snippets.

@jinfeijie
Created November 20, 2016 07:01
Show Gist options
  • Save jinfeijie/957443069b3461df8c16cf5ecfe653a5 to your computer and use it in GitHub Desktop.
Save jinfeijie/957443069b3461df8c16cf5ecfe653a5 to your computer and use it in GitHub Desktop.
温度传感器
int pin = A1;
int tempc = 0;
int samples[8];
int maxi = -100,mini = 100;
int i;
void setup(){
pinMode(pin,INPUT);
}
void loop(){
for(i = 0;i<=7;i++)
{
samples[i] = ( 5.0 * analogRead(pin) * 100.0) / 1024.0;
tempc = tempc + samples[i];
delay(100);
}
tempc = tempc/8.0;
printf("%d\n",tempc);
delay(100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment