zoukankan      html  css  js  c++  java
  • 用Tinkercad学arduino之 光线控制彩灯

    const byte O = OUTPUT;
    const byte I = INPUT;
    const byte H = HIGH;
    const byte L = LOW;
    
    const int serialPort = 9600;
    
    const int redLedPin = 11;
    const int greenLedPin = 9;
    const int blueLedPin = 10;
    
    const int redSensorPin = A0;
    const int greenSensorPin = A1;
    const int blueSensorPin = A2;
    
    const int mapSensorValueMin = 54;
    const int mapSensorValueMax = 974;
    const int mapColorValueMin = 0;
    const int mapColorValueMax = 255;
    
    int redValue = 0;
    int greenValue = 0;
    int blueValue = 0;
    
    int redSensorValue = 0;
    int greenSensorValue = 0;
    int blueSensorValue = 0;
    
    void setup()
    {
      Serial.begin(serialPort);
      
      pinMode(redLedPin, O);
      pinMode(greenLedPin, O);
      pinMode(blueLedPin, O);
    }
    
    void loop()
    {
      redSensorValue = analogRead(redSensorPin);
      delay(5);
      
      greenSensorValue = analogRead(greenSensorPin);
      delay(5);
      
      blueSensorValue = analogRead(blueSensorPin);
      delay(5);
      
      Serial.print("
    Raw Sensor Values 	 Red :");
      Serial.print(redSensorValue);
      Serial.print("	 Green:");
      Serial.print(greenSensorValue);
      Serial.print("	 Blue:");
      Serial.print(blueSensorValue);
      
      redValue = map(redSensorValue, mapSensorValueMin, mapSensorValueMax, mapColorValueMin, mapColorValueMax);
      greenValue = map(greenSensorValue, mapSensorValueMin, mapSensorValueMax, mapColorValueMin, mapColorValueMax);
      blueValue = map(blueSensorValue, mapSensorValueMin, mapSensorValueMax, mapColorValueMin, mapColorValueMax);
      
      analogWrite(redLedPin, redValue);
      analogWrite(greenLedPin, greenValue);
      analogWrite(blueLedPin, blueValue);
      
      delay(300);
    }
  • 相关阅读:
    反向代理与正向代理
    vs2017 调试时出现 cannot connect to runtime process错误
    .net core 配置swagger遇到的坑
    VC++下使用ADO操作数据库
    [转] CSS transition
    Javascript 函数和模块定义
    Service 如何知道caller
    [转] json in javascript
    [转] 让ctags支持Javascript
    [转] 使用NVM快速搭建NODE开发环境
  • 原文地址:https://www.cnblogs.com/meetrice/p/14078788.html
Copyright © 2011-2022 走看看