で、可変抵抗のアナログ値を取得できました
これを↓に組み合わせて表示してみようと思います
LED Matrix Displayになんとなくそれっぽいものを表示してみた
ねらいとしては、
Arduinoで可変抵抗からのアナログ値を取得して、
LED Matrix Displayをリアルタイムな値で更新・表示してみる
です
これも、メーター作成のテストプログラミングですね。。。
仕様っぽいもの
- 可変抵抗(ボリュームスイッチ)から、アナログ値を取得する
(可変抵抗からは0~1023までの値が取得できます - シフトインジケータに、
アナログ値を180で割って1足したものを表示する
(180で割ったのは、なんとなくそれっぽい値になったからです - 回転数を、
アナログ値を10で掛けたものを表示する
(10でかけたのは、なんとなくそれっぽい値になったからです - 速度を、
アナログ値を8で割ったものを表示する
(8で割ったのは、なんとなくそれっぽい値になったからです
値は、きほんなんとなくです
フロー的なもの
↓こんな感じですかね
表示位置
シフトインジケータ、
回転数、
速度、
それぞれ↓らへんに表示させてます
スケッチ
プログラミングしたソースです↓
#include <Adafruit_GFX.h> // Core graphics library #include <RGBmatrixPanel.h> // Hardware-specific library // 32*64 size pinassign #define OE 9 #define LAT 10 #define CLK 11 #define A A0 #define B A1 #define C A2 #define D A3 // Variable resistor pinassign #define VR A15 // Shift Indicator Text #define posShiftTextX 0 #define posShiftTextY 0 // Shift Indicator #define posShiftX 24 #define posShiftY 0 // Revolution #define posRevNumX 35 #define posRevNumY 0 // Speed #define posSpeedX 17 #define posSpeedY 18 // Speed Text #define posSpeedTextX 53 #define posSpeedTextY 25 // Shift Indicator Area #define posShiftAreaX 6 #define posShiftAreaY 7 // Revolution Area #define posRevNumAreaX 30 #define posRevNumAreaY 7 // Speed Area #define posSpeedAreaX 36 #define posSpeedAreaY 14 // Shift Indicator Text Color unsigned long colorShiftText; // Shift Indicator Color unsigned long colorShift; // Revolution Color unsigned long colorRevolution; // Speed Color unsigned long colorSpeed; // Speed Text Color unsigned long colorSpeedText; // Fill Color unsigned long colorFill; RGBmatrixPanel matrix(A, B, C, D, CLK, LAT, OE, false, 64); // Analog value of variable resistance int analogValue = 0; void initialize() { matrix.begin(); // color of the Shift Indicator Text to white colorShiftText = matrix.Color333(7, 7, 7); // color of the Shift Indicator to white colorShift = matrix.Color333(0, 7, 0); // color of the Revolution to white colorRevolution = matrix.Color333(0, 4, 7); // color of the Speed to white colorSpeed = matrix.Color333(0, 0, 7); // color of the Speed Text to white colorSpeedText = matrix.Color333(7, 7, 7); // color of the Fill Color to white colorFill = matrix.Color333(0, 0, 0); // clear the whole screen matrix.fillScreen(colorFill); // Don't wrap at end of line - will do ourselves matrix.setTextWrap(false); } void drawTextArea() { // Print Shift Indicator Text "Sht:" in white matrix.setTextSize(1); matrix.setCursor(posShiftTextX, posShiftTextY); matrix.setTextColor(colorShiftText); matrix.print("Sft:"); // Print Speed Text "km" in white matrix.setTextSize(1); matrix.setCursor(posSpeedTextX, posSpeedTextY); matrix.setTextColor(colorSpeedText); matrix.print("km"); } void setup() { // initialize the meter initialize(); // draw a text area drawTextArea(); } void loop() { char buff[10]; // get the analog value of the variable resistance analogValue = analogRead(VR); // Clear the Shift Indicator Area matrix.fillRect(posShiftX, posShiftY, posShiftAreaX, posShiftAreaY, colorFill); // Convert snprintf(buff, 10, "%d", analogValue / 180 + 1); // Draw the shift indicator area in green matrix.setTextSize(1); matrix.setCursor(posShiftX, posShiftY); matrix.setTextColor(colorShift); matrix.print(buff); // Clear the Revolution Area matrix.fillRect(posRevNumX, posRevNumY, posRevNumAreaX, posRevNumAreaY, colorFill); // Convert snprintf(buff, 10, "%5d", analogValue * 10); // Draw the Revolution in light blue matrix.setTextSize(1); matrix.setCursor(posRevNumX, posRevNumY); matrix.setTextColor(colorRevolution); matrix.print(buff); // Clear the Speed Area matrix.fillRect(posSpeedX, posSpeedY, posSpeedAreaX, posSpeedAreaY, colorFill); // Convert snprintf(buff, 10, "%3d", analogValue / 8); // Draw the Speed in blue // Print Speed in blue matrix.setTextSize(2); matrix.setCursor(posSpeedX, posSpeedY); matrix.setTextColor(colorSpeed); matrix.print(buff); // Stop for 250 ms delay(50); }
回転数のライン表示だけ、
うまくいきませんでした。。。
もう少し考えてみます。。。