10K電位器
出自YFRobotwiki
創建縮圖錯誤: 檔案似乎遺失:
產品簡介
10K電位器採用WH148 10K電位器,3引腳直接焊接杜邦線,連接更方便!
規格參數
- 供電電壓:DC5V
- 阻值:10KΩ
- 耐電壓:AC 250 V
- 絕緣阻抗:More than 100MΩ
- 開關接觸阻抗:< 50mΩ
- 開關額定功率:1.0A at AC/DC 12V
- 全迴轉角度:300±10度
- 旋轉力距:20~200 gf.cm
- 旋轉止動強度:6.0Kgf.cm Min
- 旋轉壽命:10000 Cycles
- 模塊尺寸:29*20*35MM(長*寬*高)
- 模塊重量:13.0g
引腳說明
- 1. G 黑線 -- Gnd(地)
- 2. V 紅線 -- Vcc(電源+5V)
- 3. S 白線 -- 信號
應用示例
電路連接示意圖
- 搖桿模塊的 G、V、S分別連接 Arduino UNO的GND、VCC(+5V)、A0引腳。
示例代碼
示例一:電位器值串口打印
/* Potentiometer Test */ int pPin = A0; int pVal = 0; int pVal_old = 0; void setup() { pinMode(pPin,INPUT); Serial.begin(9600); } void loop() { //读取A0模拟口的数值(0-5V 对应 0-1204取值) pVal = analogRead(pPin); if(abs(pVal - pVal_old) >= 2 ){ Serial.println(pVal); pVal_old = pVal; } }
程序下載地址:PotentiometerTest
程序運行結果:電位器值串口打印,結果如下圖:
創建縮圖錯誤: 檔案似乎遺失:
示例二:電位器控制彩色LED模塊變色
/* Potentiometer control RGB LED change color */ #include <Adafruit_NeoPixel.h> #define RGBLEDPin 5 #define NUMPIXELS 4 #define pPin A0 // Parameter 1 = number of pixels in strip // Parameter 2 = pin number (most are valid) // Parameter 3 = pixel type flags, add together as needed: // NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) // NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) // NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) // NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, RGBLEDPin, NEO_GRB + NEO_KHZ800); int pVal = 0; int RVal = 0; int GVal = 0; int BVal = 0; void setup() { pinMode(RGBLEDPin, OUTPUT); pixels.begin(); // This initializes the NeoPixel library. pixels.show(); } void loop() { pVal = analogRead(pPin); //读取A0模拟口的数值(0-5V 对应 0-1203取值) if (pVal >= 0 && pVal <= 170) { RVal = 255; GVal = 0; BVal = map(pVal, 0, 170, 0, 255); } else if (pVal > 170 && pVal <= 340) { RVal = map(pVal, 170, 340, 255, 0); GVal = 0; BVal = 255; } else if (pVal > 340 && pVal <= 510) { RVal = 0; GVal = map(pVal, 340, 510, 0, 255); BVal = 255; } else if (pVal > 510 && pVal <= 680) { RVal = 0; GVal = 255; BVal = map(pVal, 510, 680, 255, 0); } else if (pVal > 680 && pVal <= 850) { RVal = map(pVal, 680, 850, 0, 255); GVal = 255; BVal = 0; } else { RVal = 255; GVal = map(pVal, 850, 1023, 255, 0); BVal = 0; } lightLED(RVal, GVal, BVal); } void lightLED(int r, int g , int b) { // For a set of NeoPixels the first NeoPixel is 0, second is 1, all the way up to the count of pixels minus one. for (int i = 0; i < NUMPIXELS; i++) { // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255 pixels.setPixelColor(i, r, g, b); // Moderately bright green color. pixels.show(); // This sends the updated pixel color to the hardware. } }
程序下載地址:ChangeColor
程序運行結果:轉動電位器,彩色led變色。點擊查看視頻:[ ]
更多建議和問題歡迎反饋至 YFRobot論壇
購買方式:YFRobot 電子工作室