Hello!!
Im new to arduino and blynk app but im starting a project using rf relays that i bought on eBay, these came with code prewritten because i don't have much coding skills and i was wondering if anyone could help adapt the code to use virtual pins instead of the serial commands form a pc
from the blynk support i got this:
"Virtual Pins
Blynk can control Digital and Analog IO Pins on you hardware directly. You don’t even need to write code for it. It’s great for blinking LEDs, but often it’s just not enough…
We designed Virtual Pins to send any data from your microcontroller to the Blynk App and back.
It opens huge opportunities for you, because anything you plug in to your hardware will be able to talk to Blynk. With Virtual Pins you can send something from the App, process it on Arduino and then send it back to the smartphone based on any logic you want. You can trigger functions, read I2C devices, convert values, control any servo motor and so on.
Virtual Pins can be used to interface with external libraries (Servo, LCD and others) and implement custom functionality. The device may send data to the Widgets to the Virtual Pin like this:
Blynk.virtualWrite(pin, "abc");
Blynk.virtualWrite(pin, 123);
Blynk.virtualWrite(pin, 12.34);
Send data from app to hardware
You can send any data from Widgets in the app to your hardware.
All Controller Widgets can send data to Virtual Pins on your hardware. For example, code below shows how to get values from the Button Widget in the App
BLYNK_WRITE(V1) //Button Widget is writing to pin V1
{
int pinData = param.asInt();
}
When you press Button, Blynk App sends 1 On second click - it sends 0
and the code that i got from the relays is this:
//Author: cantone-electonics
//More information welcome to : http://www.canton-electronics.com
//Arduino 1.0
//Arduino uno R3
//Making a wireless remote control with arduino
//const int data_out = 2;//encoder DOUT
//LED pin,When receiving the key from the serial port, LED flash
const int ledPin = 13; //LED pin
const int gnd_pin = 9; //AS GND
const int data_out = 10; //encoder DOUT
const int vcc_pin= 11; //AS VCC
// OSC Resistance is 3.3M
const int Osc_4xCycle = 359; //4 oscillating time periods
const int Osc_12xCycle = 1078;//12 oscillating time periods
unsigned long Temporary[3];//Temporary storage unit
//output bit "0"
void bit_0() {
digitalWrite(data_out, HIGH);
delayMicroseconds(Osc_4xCycle);//4 oscillating time periods High level
digitalWrite(data_out, LOW);
delayMicroseconds(Osc_12xCycle);//12 oscillating time periods Low level
digitalWrite(data_out, HIGH);
delayMicroseconds(Osc_4xCycle);//4 oscillating time periods High level
digitalWrite(data_out, LOW);
delayMicroseconds(Osc_12xCycle);//12 oscillating time periods Low level
}
//output bit "1"
void bit_1() {
digitalWrite(data_out, HIGH);
delayMicroseconds(Osc_12xCycle);//12 oscillating time periods High level
digitalWrite(data_out, LOW);
delayMicroseconds(Osc_4xCycle);//4 oscillating time periods Low level
digitalWrite(data_out, HIGH);
delayMicroseconds(Osc_12xCycle);//12 oscillating time periods High level
digitalWrite(data_out, LOW);
delayMicroseconds(Osc_4xCycle);//4 oscillating time periods Low level
}
//output bit "f"
void bit_f() {
digitalWrite(data_out, HIGH);
delayMicroseconds(Osc_4xCycle);//4 oscillating time periods High level
digitalWrite(data_out, LOW);
delayMicroseconds(Osc_12xCycle);//12 oscillating time periods Low level
digitalWrite(data_out, HIGH);
delayMicroseconds(Osc_12xCycle);//12 oscillating time periods High level
digitalWrite(data_out, LOW);
delayMicroseconds(Osc_4xCycle);//4 oscillating time periods Low level
}
//output synchronous bit
void bit_syn() {
digitalWrite(data_out, HIGH);
delayMicroseconds(Osc_4xCycle);//4 oscillating time periods High level
digitalWrite(data_out, LOW);
delayMicroseconds(Osc_4xCycle*31);//124 oscillating time periods Low level
}
//send:8 Address Bits, 4 Data Bits, Sync bit
void send_data(){
unsigned char temp,tab,i;
unsigned char j,k;
for(j=0;j<4;j++)
{
for(k=0;k<3;k++)//send 8 Address Bits, 4 Data Bits
{
tab = Temporary[k];
for(i=0;i<4;i++)
{
temp = tab;
temp &= 0xC0;
if(temp == 0xC0)//11 is bit "1"
{
bit_1();
}
else if(temp == 0x00)//00 is bit "0"
{
bit_0();
}
else //01 is bit "f"
{
bit_f();
}
tab = tab << 2;
}
}
bit_syn();//send Sync bit
}
}
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the encoder DOUT pin as an output
pinMode(data_out, OUTPUT);
pinMode(gnd_pin, OUTPUT);
pinMode(vcc_pin, OUTPUT);
digitalWrite(vcc_pin, HIGH);//SET VCC
digitalWrite(gnd_pin, LOW);//SET GND
Serial.begin(9600);
}
void loop()
{
int keydata = 0;
int receive_flag = 0;
Temporary[0] = 0xC5;//address A7-A4
Temporary[1] = 0x55;//address A3-A0
digitalWrite(ledPin, LOW);//Turn off led
while(1)
{
//get key from pc serial port
while (Serial.available() > 0)
{
keydata = Serial.read();
receive_flag = 1;
delay(2);
}
if(receive_flag == 1)//if get key,send key
{
receive_flag = 0;
if((keydata == 'a') || (keydata == 'A'))//trigger A channel relay.
{
Temporary[2] = 0xC0;// 0xC0 is A button key
digitalWrite(ledPin, HIGH);//Turn on led
send_data();//send code word
Serial.println(".....trigger A channel relay.....");
}
else if((keydata == 'b') || (keydata == 'B'))//trigger B channel relay.
{
Temporary[2] = 0x30;// 0x30 is B button key
digitalWrite(ledPin, HIGH);//Turn on led
send_data();//send code word
Serial.println(".....trigger B channel relay.....");
}
else if((keydata == 'c') || (keydata == 'C'))//trigger C channel relay.
{
Temporary[2] = 0x0C;// 0x0C is C button key
digitalWrite(ledPin, HIGH);//Turn on led
send_data();//send code word
Serial.println(".....trigger C channel relay.....");
}
else if((keydata == 'd') || (keydata == 'D'))//trigger D channel relay.
{
Temporary[2] = 0x03;// 0x03 is D button key
digitalWrite(ledPin, HIGH);//Turn on led
send_data();//send code word
Serial.println(".....trigger D channel relay.....");
}
keydata = 0;
//When receiving the key from the serial port, LED flash
digitalWrite(ledPin, LOW);//Turn off led
delay(50);//delay 100ms
digitalWrite(ledPin, HIGH);//Turn on led
delay(50);//delay 100ms
digitalWrite(ledPin, LOW);//Turn off led
delay(50);//delay 100ms
digitalWrite(ledPin, HIGH);//Turn on led
delay(50);//delay 100ms
digitalWrite(ledPin, LOW);//Turn off led
}
}
}
i would be forever thankfull if anyone could help me, i know its a bit of a stretch... thank you