0

現在、Arduinoからパルスを読み取り、結果がHighかLowかを確認する必要があるプロジェクトに取り組んでいます。

Arduino から高/低出力を生成するには、独自のコードを作成する必要がありました。

//Pulse Generator Arduino Code  
int potPin = 2;    // select the input pin for the knob
int outputPin = 13;   // select the pin for the output
float val = 0;       // variable to store the value coming from the sensor

void setup() {
  pinMode(outputPin, OUTPUT);  // declare the outputPin as an OUTPUT
  Serial.begin(9600);
}

void loop() {
  val = analogRead(potPin);    // read the value from the k
  val = val/1024;
  digitalWrite(outputPin, HIGH);    // sets the output HIGH
  delay(val*1000);
  digitalWrite(outputPin, LOW);    // sets the output LOW
  delay(val*1000);
}

ノブを使用して、パルス間の遅延を変更します。

私は現在、「outputPin」からカウントArduinoのポートにケーブルで2を接続するだけで、別のArduino(これを「カウントArduino 」と呼びましょう)で高/低データを読み取ろうとしています。

私は digitalRead を使用して、遅滞なくポートを読み取っています。

//Count Arduino Code
int sensorPin = 22;
int sensorState = 0;

void setup()   {                
    pinMode(sensorPin, INPUT);
    Serial.begin(9600);
}

void loop(){
    sensorState = digitalRead(sensorPin);
    Serial.println(sensorState);
}

最初は 1 秒ごとにパルスを送信しようとしましたが、結果は大量の低値と高値のスパムでした。常に 3 つの安値と 3 つの高値を繰り返します。それは 1 秒に 1 回というよりも、1 ミリ秒に 1 回という感じでした。

私は自分が間違っていることを理解できません。タイミングの問題ですか、それともこれらの変更を検出するためのより良い方法はありますか?

4

1 に答える 1