I’ve got bridge going on my project and it is only sorta working. I’m trying to send a number between 0-7. On the sending unit when I press a button it changes the value of V1 then that value gets sent. In the app I’m seeing the correct number that is supposed to be sent. In the receiving unit whenever I press a button it only gets a 1 on V1. Very weird. I know the two are communicating, but the number is wrong.
Sending unit code
//#define DEBUG // Comment this out to disable debug prints
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#define Buttons A0
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YOUR AUTH";
char ssid[] = "SSID";
char pass[] = "PASS";
// Bridge widget on virtual pin 1
WidgetBridge bridge1(V1);
int current = 0;
int last = -1;
int ButtonRead = 0;
void blynkAnotherDevice()
{
Serial.println(analogRead(Buttons));
ButtonRead = analogRead(Buttons);
delay(1);
// grab the current state of the remote-buttons
if (ButtonRead > 50 && ButtonRead < 115) {
current = 1;
}
if (ButtonRead > 115 && ButtonRead < 130) {
current = 2;
}
if (ButtonRead > 130 && ButtonRead < 150) {
current = 3;
}
if (ButtonRead > 150 && ButtonRead < 180) {
current = 4;
}
if (ButtonRead > 180 && ButtonRead < 220) {
current = 5;
// spark1.virtualWrite(V1, 5);
}
if (ButtonRead > 220 && ButtonRead < 280) {
current = 6;
}
if (ButtonRead > 280 && ButtonRead < 400) {
current = 7;
}
if (ButtonRead > 900) {
current = 0;
}
Serial.println(current);
// return if the value hasn't changed
if(current == last)
return;
bridge1.virtualWrite(V1, current);
last = current;
}
BLYNK_READ(V1)
{
Blynk.virtualWrite(V1, current);
}
void setup()
{
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
while (Blynk.connect() == false) {
// Wait until connected
}
}
BLYNK_CONNECTED() {
bridge1.setAuthToken("Target Auth"); // Place the AuthToken of the second hardware here
}
void loop()
{
Blynk.run();
blynkAnotherDevice();
}
Receiving unit code
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <Adafruit_NeoPixel.h>
#include <BlynkSimpleEsp8266.h>
/****************************** neopixels ******************************************/
#define NUM_PIXELS 16
/************************* WiFi Access Point *********************************/
#define WLAN_SSID "ssid"
#define WLAN_PASS "pass"
Adafruit_NeoPixel pixels(NUM_PIXELS, 2, NEO_GRB | NEO_KHZ800);
uint32_t Pixel1 = pixels.Color(255, 255, 255); //white
uint32_t Pixel2 = pixels.Color(255, 0, 0); //Red
uint32_t Pixel3 = pixels.Color(0, 255, 0); //Green
uint32_t Pixel4 = pixels.Color(255, 255, 0); //amber
uint32_t Pixel5 = pixels.Color(0, 0, 255); //Blue
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "AUTH";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "SSID";
char pass[] = "PASS";
int current = 0;
void setup() {
Blynk.begin(auth, ssid, pass);
pixels.begin();
Serial.begin(115200);
}
BLYNK_WRITE(V1)
{int current = param.asInt(); // assigning incoming value from pin V1 to a variable
if (current = 1){Spark1();}
else if (current = 2) {Spark2();}
else if (current = 3) {Spark3();}
else if (current = 4) {Spark4();}
else if (current = 5) {Spark5();}
else if (current = 6) {Spark0();}
Serial.print("V1 value is: ");
Serial.println(current);
}
BLYNK_READ(V1)
{
Blynk.virtualWrite(V1, current);
}
void loop() {
Blynk.run();
}
void Spark0() {
colorWipe(pixels.Color(0, 0, 0), 500); // Black/off
pixels.show();
}
void Spark1() {
pixels.setPixelColor(0, Pixel1);
pixels.setPixelColor(1, Pixel1);
pixels.setPixelColor(2, Pixel1);
pixels.show();
}
void Spark2()
{
pixels.setPixelColor(3, Pixel2);
pixels.setPixelColor(4, Pixel2);
pixels.setPixelColor(5, Pixel2);
pixels.show();
}
void Spark3 () {
pixels.setPixelColor(6, Pixel3);
pixels.setPixelColor(7, Pixel3);
pixels.setPixelColor(8, Pixel3);
pixels.show();
}
void Spark4() {
pixels.setPixelColor(9, Pixel4);
pixels.setPixelColor(10, Pixel4);
pixels.setPixelColor(11, Pixel4);
pixels.show();
}
void Spark5() {
pixels.setPixelColor(12, Pixel5);
pixels.setPixelColor(13, Pixel5);
pixels.setPixelColor(14, Pixel5);
pixels.show();
}
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<pixels.numPixels(); i++) {
pixels.setPixelColor(i, c);
pixels.show();
delay(wait);
}}