[英]Analog Input To Change RGB Color
I am setting up a rotary angle sensor for my analog changer.我正在为我的模拟转换器设置一个旋转角度传感器。 There is a digital display to show where we are within the range.
有一个数字显示器来显示我们在范围内的位置。 What I am trying to do is create a color range with the analog range but are unable to figure out how to make the colors change with the analog range.
我想要做的是用模拟范围创建一个颜色范围,但无法弄清楚如何使颜色随着模拟范围而变化。
// This #include statement was automatically added by the Particle IDE.
#include <Grove_ChainableLED.h>
// This #include statement was automatically added by the Particle IDE.
#include <Grove_4Digit_Display.h>
#define NUM_LEDS 1
ChainableLED leds(D2, D3, NUM_LEDS);
#define POT1 A0
#define LED1 D2
#define CLK D4
#define DIO D5
TM1637 tm1637(CLK,DIO);
int analogValue = 0;
float hue = 0.0;
void setup()
{
pinMode(LED1 , OUTPUT);
pinMode(POT1 , INPUT);
tm1637.set();
tm1637.init();
Serial.begin(9600);
}
void loop()
{
analogValue = analogRead(POT1);
hue = analogValue;
analogWrite(LED1, map(analogValue, 0, 4095, 0, 255));
tm1637.display(0, (analogValue / 1000));
tm1637.display(1, (analogValue % 1000 /100));
tm1637.display(2, (analogValue % 100 /10));
tm1637.display(3, (analogValue % 10));
leds.setColorHSB(0, map(hue, 0.0, 4095.0, 0.0, 1.0), 1.0, 0.2);
delay(200);
}
I was able to redirect how I was looking into having the light change color.我能够重定向我如何看待灯光变色。 Overall I was able to make it work.
总的来说,我能够让它发挥作用。 The digital display worked with the knob being turned, then once it reaches 2000 the color changes.
数字显示在转动旋钮的情况下工作,一旦达到2000,颜色就会发生变化。
// This #include statement was automatically added by the Particle IDE.
#include <Grove_ChainableLED.h>
// This #include statement was automatically added by the Particle IDE.
#include <TM1637Display.h>
// This #include statement was automatically added by the Particle IDE.
#include <Grove_4Digit_Display.h>
#define POT1 A0
#define CLK D4
#define DIO D5
#define NUM_LEDS 1
TM1637 tm1637(CLK,DIO);
ChainableLED leds(D2, D3, NUM_LEDS);
int analogValue;
int hue = 0.0;
void setup()
{
pinMode(POT1 , INPUT);
tm1637.set();
tm1637.init();
leds.init();
Particle.variable("Displayed_Number", analogValue);
leds.setColorRGB(0, 0, 0, 255);
}
void loop()
{
//Reading Input From Knob Turning
analogValue = analogRead(POT1);
hue = analogValue;
tm1637.display(0, (analogValue / 1000));
tm1637.display(1, (analogValue % 1000 /100));
tm1637.display(2, (analogValue % 100 /10));
tm1637.display(3, (analogValue % 10));
delay(200);
if (analogValue > 2000) {
//Turn Light On When Above Number
leds.setColorRGB(0, 255, 0, 0);
}
if (analogValue <= 2000) {
//Light Is Off If Below Number
leds.setColorRGB(0, 0, 255, 0);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.