|
求各位高手救援,小弟我最近為了專題一直在研究Arduino的程式編寫和結合
程式分別是
結合前:
315Mhz無線收發模組
發射程式:
#include <VirtualWire.h>
const char *a = "a";
const char *b = "b";
void setup()
{
vw_set_ptt_inverted(true);
vw_setup(2400);
vw_set_tx_pin(1);
}
void loop()
{
delay(1000);
vw_send((uint8_t *)a, strlen(a));
vw_wait_tx();
delay(1000);
vw_send((uint8_t *)b, strlen(b));
vw_wait_tx();
}
接收:
#include <VirtualWire.h>
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
const int LED = 13;
void setup()
{
pinMode(LED, OUTPUT);
digitalWrite(LED,LOW);
vw_set_ptt_inverted(true);
vw_setup(2400);
vw_set_rx_pin(0);
vw_rx_start();
}
void loop()
{
if (vw_get_message(buf, &buflen)) {
switch(buf[0])
{
case 'a':
digitalWrite(LED,HIGH);
break;
case 'b':
digitalWrite(LED,LOW);
break;
}
}
}
和電流感應模組:
void setup() {
Serial.begin(9600);
}
void loop() {
float value = analogRead(A0);
Serial.println((((value-511)*5)/1023)/0.115);
if ((((value-511)*5)/1023)/0.115>2.1)
Serial.println(String("")+"a");
else
Serial.println((((value-511)*5)/1023)/0.115);
delay(500);
}
結合後:
發射:
#include <VirtualWire.h>
const char *a = "a";
const char *b = "b";
void setup() {
Serial.begin(9600);
vw_set_ptt_inverted(true);
Serial.begin(9600);
vw_setup(2400);
vw_set_tx_pin(1);
}
void loop() {
float value = analogRead(A0);
Serial.println((((value-511)*5)/1023)/0.115);
if ((((value-511)*5)/1023)/0.115>2.1)
{
digitalWrite(13,true);
vw_send((uint8_t *)a, strlen(a));
vw_wait_tx();
digitalWrite(13,false);
delay(1000);
}
else
vw_send((uint8_t *)b, strlen(b));
Serial.println((((value-511)*5)/1023)/0.115);
delay(500);
}
接收:
#include <VirtualWire.h>
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
const int LED = 13;
void setup()
{
Serial.begin(9600);
pinMode(LED, OUTPUT);
digitalWrite(LED,LOW);
vw_set_ptt_inverted(true);
vw_setup(2400);
vw_set_rx_pin(0);
vw_rx_start();
}
void loop()
{
if (vw_get_message(buf, &buflen)) {
switch(buf[0])
{
case 'a':
digitalWrite(LED,HIGH);
break;
case 'b':
digitalWrite(LED,LOW);
break;
}
}
}
結合前的程式分別驗證的時侯都OK,但是結合後315Mhz模組卻沒有反應,請各位高手幫小弟看一下問題在哪裡,拜託了 |
|