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);
    }
  • 相关阅读:
    学习Python用来爬虫
    C# 校验帮助类-正则表达式
    关于网站使用异步请求以后浏览器源码查看不到数据导致百度抓取不到的问题解决方案
    Linq学习教程
    【jQuery】选择器
    【jQuery】初始化的三种方法
    【ueditor】api方法
    同步(Synchronous)和异步(Asynchronous)
    【postman】postman
    【mysql函数】FIND_IN_SET函数用法
  • 原文地址:https://www.cnblogs.com/meetrice/p/14078788.html
Copyright © 2011-2022 走看看