LedControl и VirtualWire
- Войдите на сайт для отправки комментариев
Сб, 18/10/2014 - 00:17
Добрый день,
подскажите пожалуйста -- есть такая проблема: использую в одном скетче LedControl для управления светодиодной матрицей и VirtualWire с радио модулем, для получения данных по радио. Проблема в следующем -- при активации матрицы перестаёт работать приём. Т.е. просто данные не приходят. Как только комментирую строчку запуска матрицы, то сразу всё хорошо.
lc.shutdown(0,false); // вот эта строчка, которая будит матрицу и с ней не работает радио-приём, а без неё работает.
Полный код скетча:
#include <EEPROM.h> //Needed to access the eeprom read write functions
#include <LedControl.h>
#include <VirtualWire.h>
#include <EasyTransferVirtualWire.h>
#define PIN_LED (13) // INDICATOR
#define PIN_RF (2)
#define PIN_LCD_DATA (6)
#define PIN_LCD_CLK (5)
#define PIN_LCD_LOAD (4)
#define NUMBER_OF_MATRIX (1)
#define CLASS_MATRIX (26) // control class command
String inData;
unsigned int unique_device_id = 0;
LedControl lc=LedControl(PIN_LCD_DATA,PIN_LCD_CLK,PIN_LCD_LOAD,CLASS_MATRIX);
long int uptime = 0;
long int old_uptime = 0;
unsigned int packet_received_id = 0;
EasyTransferVirtualWire ET;
struct SEND_DATA_STRUCTURE {
//put your variable definitions here for the data you want to send
//THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO
//Struct can'e be bigger then 26 bytes for VirtualWire version
unsigned int device_id;
unsigned int destination_id;
unsigned int packet_id;
byte command;
int data;
};
//give a name to the group of data
SEND_DATA_STRUCTURE mydata;
//This function will write a 2 byte integer to the eeprom at the specified address and address + 1
void EEPROMWriteInt(int p_address, unsigned int p_value)
{
byte lowByte = ((p_value >> 0) & 0xFF);
byte highByte = ((p_value >> 8) & 0xFF);
EEPROM.write(p_address, lowByte);
EEPROM.write(p_address + 1, highByte);
}
//This function will read a 2 byte integer from the eeprom at the specified address and address + 1
unsigned int EEPROMReadInt(int p_address)
{
byte lowByte = EEPROM.read(p_address);
byte highByte = EEPROM.read(p_address + 1);
return ((lowByte << 0) & 0xFF) + ((highByte << 8) & 0xFF00);
}
void blinking(int count) {
for(int i=0;i<count;i++) {
digitalWrite(PIN_LED, HIGH);
delay(200);
digitalWrite(PIN_LED, LOW);
delay(200);
}
}
void writeOnMatrix(int value1) {
byte a[8]={B00000000,
B01100110,
B11111111,
B11111111,
B01111110,
B00111100,
B00011000,
B00000000
};
lc.setRow(0,0,a[0]);
lc.setRow(0,1,a[1]);
lc.setRow(0,2,a[2]);
lc.setRow(0,3,a[3]);
lc.setRow(0,4,a[4]);
lc.setRow(0,5,a[5]);
lc.setRow(0,6,a[6]);
lc.setRow(0,7,a[7]);
}
void setup()
{
randomSeed(analogRead(0));
pinMode(PIN_LED, OUTPUT);
Serial.begin(9600); // Debugging only
/*
The MAX72XX is in power-saving mode on startup,
we have to do a wakeup call
*/
lc.shutdown(0,false);
/* Set the brightness to a medium values */
lc.setIntensity(0,8);
/* and clear the display */
lc.clearDisplay(0);
//lc.shutdown(0,true);
ET.begin(details(mydata));
// Initialise the IO and ISR
vw_set_rx_pin(PIN_RF);
vw_setup(2000); // Bits per sec
vw_rx_start(); // Start the receiver PLL running
// Device ID
Serial.print("Getting Device ID... ");
unique_device_id=EEPROMReadInt(0);
if (unique_device_id<10000 || unique_device_id>60000 || unique_device_id==26807) {
Serial.print("N/A, updating... ");
unique_device_id=random(10000, 60000);
EEPROMWriteInt(0, unique_device_id);
}
Serial.println(unique_device_id);
writeOnMatrix(1);
}
void loop()
{
uptime=round(millis()/1000);
if (uptime!=old_uptime) {
Serial.print("Up: ");
Serial.println(uptime);
old_uptime=uptime;
}
//begin easy transfer
if (ET.receiveData()) {
Serial.print("Got packet for device ");
Serial.print(mydata.destination_id);
Serial.print(" packet ");
Serial.print(mydata.packet_id);
Serial.print(" command ");
Serial.print(mydata.command);
Serial.print(" data ");
Serial.println(mydata.data);
if ((mydata.command==CLASS_MATRIX) && (mydata.packet_id!=packet_received_id)) {
Serial.print("Got RF command: ");
Serial.print(mydata.command);
Serial.print(" data: ");
Serial.println(mydata.data);
packet_received_id=(int)mydata.packet_id;
} else {
Serial.println("Ignoring packet.");
}
}
if (Serial.available()) {
char c=Serial.read();
if (c == '\n' || c == ';')
{
Serial.println(inData);
int commandProcessed=0;
if (inData.equals("blink")) {
Serial.println("BLINKING!");
blinking(3);
commandProcessed=1;
}
inData="";
Serial.flush();
} else {
inData += (c);
}
}
}