I am a newbie to Arduino and created my first project. The project is using a Sharp short range sensor and a 7 seg LED board (http://embedded-lab.com/blog/new-version-of-max7219-based-4-digit-serial-seven-segment-led-display/) to count objects.
私のコンピュータにUSB電源を供給しているとき、またはUSBケーブルを使って5V 1Aの壁アダプタを使用すると、すべて正常に動作します。問題は、外部電源アダプタを使用するか、またはVinにDC電源を使用する場合です。ボードの電源が入り、5Vピンの出力電圧を測定して約4.8Vを測定しています。
シャープセンサーはA0アナログ入力に接続されています。オブジェクトが通過すると電圧が変動するのがわかりますが、外部電源ではLEDが値を表示していません。ディスプレイはGRD、5Vに接続されています。ディスプレイのDIN、CLK、およびLOADピンは、説明されているようにピン7,6、および5に接続されています。
私は2つの異なるArduinoボードといくつかの異なるAC to DC電源アダプタを試しました.9Vから12Vに加え、Vinと同じ結果にDC電源を使用しました。
コードは以下の通りですが、かなりシンプルです(これはもっと良い方法があると確信していますが、これはC言語の最初のプロジェクトですので、簡単に手に入り、数字の機能はウェブサイトからのもので、私の書かれたものではありません)。
プロジェクトの写真が助けになるなら、アップロードすることができます。
任意のアイデアや考え?
ありがとう、
スティーブ
#include "LedControl.h"
#include
#include
// Arduino Pin 7 to DIN, 6 to Clk, 5 to LOAD, no.of devices is 1
LedControl lc = LedControl(7, 6, 5, 1);
int sensorpin = 0; //analog pin used to connect the sharp sensor
int val = 0; //variable to store the values from sensor(initially zero)
int cnt = 1;
void setup()
{
//Initialize the MAX7219 device
lc.shutdown(0, false); //Enable display
lc.setIntensity(0, 10); //Set brightness level (0 is min, 15 is max)
lc.clearDisplay(0); //Clear display register
}
void loop()
{
val = analogRead(sensorpin); //reads the value of the sharp sensor
if (val >= 650)
{
//write values to LED
if (cnt<=9)
{
lc.setDigit(0, 0, cnt, false);//Display 4 to Digit 1-9, " "
}
if (cnt >= 10 && cnt <= 99)
{
lc.setDigit(0, 0, getDigitFromNum(cnt,0), false);//Display 4 to Digit 1-9, " "
lc.setDigit(0, 1, getDigitFromNum(cnt, 1), false);//Display 3 to Digit 1-9, " "
}
if (cnt >=100)
{
lc.setDigit(0, 0, getDigitFromNum(cnt, 0), false);//Display 4 to Digit 1-9, " "
lc.setDigit(0, 1, getDigitFromNum(cnt, 1), false);//Display 3 to Digit 1-9, " "
lc.setDigit(0, 2, getDigitFromNum(cnt, 2), false);//Display 2 to Digit 1-9, " "
}
delay(400);
cnt++;
}
}
// Function: getDigitFromNum returns a digit at a given index of a integer.
// Goes from right to left with the starting index of 0.
int getDigitFromNum(int num, int digit) {
num /= pow(10, digit);
return num % 10;
}
// Function: getDigitFromDec returns a digit at a given index of a double.
// Goes from left to right with the starting index of 0.
int getDigitFromDec(double dec, int digit) {
dec *= pow(10, digit);
return (int)dec % 10;
}
// Function: getDigitFromNum returns the decimal values of a double.
double getDecimals(double dec) {
return dec - (int)dec;
}