zoukankan      html  css  js  c++  java
  • 用Tinkercad学arduino之 温度LED报警

    项目地址: https://www.tinkercad.com/things/cgPamtJwfSP


    // Code for `APB-03 Love-O-Meter`
    // @see https://www.tinkercad.com/things/cgPamtJwfSP
    
    const int SENSOR_PIN = A0;
    const int SENSOR_VAL_MIN = 20;
    const int SENSOR_VAL_MAX = 358;
    const int SENSOR_TEMP_MIN = -40;
    const int SENSOR_TEMP_MAX = 125;
    
    const int SERIAL_PORT = 9600;
    
    const int LED_PIN_MIN = 2;
    const int LED_PIN_MAX = 6;
    const int LED_COUNT = LED_PIN_MAX - LED_PIN_MIN + 1;
    
    const int TEMP_BASELINE_MIN = SENSOR_TEMP_MIN + 10;
    const int TEMP_BASELINE_MAX = SENSOR_TEMP_MAX - 10;
    const int TEMP_BASELINE_DELTA = TEMP_BASELINE_MAX - TEMP_BASELINE_MIN;
    const int TEMP_INTERVAL = TEMP_BASELINE_DELTA / (LED_COUNT - 1);
    
    const int lOOP_DELAY = 300;
    
    void setup()
    {
      Serial.begin(SERIAL_PORT);
      
      for(int ledPin = LED_PIN_MIN; ledPin <= LED_PIN_MAX; ledPin++) {
        pinMode(ledPin, OUTPUT);
        digitalWrite(ledPin, LOW);
      }
      
      Serial.print("Ready!");
    }
    
    void loop()
    {
      int sensorVal = analogRead(SENSOR_PIN);
      float sensorTemp = map(sensorVal, SENSOR_VAL_MIN, SENSOR_VAL_MAX, SENSOR_TEMP_MIN, SENSOR_TEMP_MAX);
      
      Serial.print("
    Sensor Value: ");
      Serial.print(sensorVal); 
      Serial.print("	degrees C: ");
      Serial.print(sensorTemp);
      
      for(int i = 0; i < LED_COUNT; i++) {
        int ledPin = LED_PIN_MIN + i;
        int tempLevel = TEMP_BASELINE_MIN + (i * TEMP_INTERVAL);
        if(sensorTemp > tempLevel) {
          digitalWrite(ledPin, HIGH);
        } else {
          digitalWrite(ledPin, LOW);
        }
      }  
      
      delay(lOOP_DELAY);
    }
  • 相关阅读:
    Python之matplotlib库学习
    Linux相关指令和操作
    ubuntu安装vim
    classfication中使用图像金字塔和sliding windows提高准确率
    ubuntu16.04+caffe+python接口配置
    caffe中 softmax 函数的前向传播和反向传播
    cplusplus解析
    ZStack之ZDApp_Init解析
    Z-Stack ZMain学习
    ZigBee协议学习之网络层
  • 原文地址:https://www.cnblogs.com/meetrice/p/14078673.html
Copyright © 2011-2022 走看看