1+ /*
2+ *******************************************************************************
3+ * Copyright (c) 2021 by M5Stack
4+ * Equipped with M5Core sample source code
5+ * 配套 M5Core 示例源代码
6+ * Visit the website for more information:https://docs.m5stack.com/cn/unit/fader
7+ * 获取更多资料请访问:https://docs.m5stack.com/en/unit/fader
8+ *
9+ * describe:UNIT FADER. 滑动电位器/推子
10+ * date:2021/8/20
11+ *******************************************************************************
12+ Connect UNIT FADER to port B and push the FADER slider to adjust the input value and light brightness
13+ 将UNIT FADER连接到B端口, 推动FADER滑杆即可实现调整输入数值大小与灯光亮度
14+ */
15+
16+ #include " M5Stack.h"
17+ #include " FastLED.h"
18+
19+ // How many leds in your strip?
20+ #define NUM_LEDS 14
21+ #define INPUT_PINS 36
22+
23+ #define DATA_PIN 26
24+
25+ // Define the array of leds
26+ CRGB leds[NUM_LEDS ];
27+
28+ uint8_t beginHue = 0 ;
29+ uint8_t deltaHue = 30 ;
30+ uint8_t brightness = 100 ;
31+ uint16_t rawADC = 0 ;
32+
33+ void setup ()
34+ {
35+ M5 .begin ();
36+ M5 .Lcd .setTextDatum (MC_DATUM );
37+ M5 .Lcd .drawString (" FADER UNIT TEST" , 160 , 60 , 4 );
38+ FastLED.addLeds <NEOPIXEL , DATA_PIN >(leds, NUM_LEDS );
39+ delay (1000 );
40+ pinMode (36 , INPUT );
41+ fill_rainbow (leds, NUM_LEDS , beginHue, deltaHue);
42+ }
43+
44+
45+ void loop ()
46+ {
47+ rawADC = analogRead (INPUT_PINS ); // Read ADC value 读取ADC数值
48+ brightness = map (rawADC, 0 , 4095 , 0 , 255 ); // The mapping ADC value is the brightness value range 映射ADC值为亮度值范围
49+ FastLED.setBrightness (brightness); // Adjust the brightness of the FADER LED 调整FADER LED灯亮度
50+ FastLED.show ();
51+ Serial.printf (" %d\r\n " , rawADC);
52+ M5 .Lcd .fillRect (0 , 120 , 320 , 100 , BLACK );
53+ M5 .Lcd .drawString (" value: " +String (rawADC), 160 , 160 , 4 );
54+ delay (100 );
55+ }
0 commit comments