Running the project

Connect to your Raspberry Pi with your computer using PuTTY through SSH:

  1. Move to the blynk-library/linux directory by issuing the following command:
pi@raspberrypi:~ $cd blynk-library/linux
  1. Open the main.cpp file by issuing the following command:
pi@raspberrypi:~/blynk-library/linux $sudonano main.cpp
  1. If not, include the software PWM library just after the WiringPi library, wiringPi.h:
#include <softPwm.h>
  1. Then, edit the setup() function as follows:
void setup()
{
Blynk.begin(auth, serv, port);
softPwmCreate(3,0,255);
softPwmCreate(21,0,255);
softPwmCreate(22,0,255);
}
  1. Finally, edit BLYNK_WRITE(V1) as follows:
BLYNK_WRITE(V1)
{
printf("Got a value: %sn", param[0].asStr());
printf("Got a value: %sn", param[1].asStr());
printf("Got a value: %sn", param[2].asStr());
softPwmWrite(3, param[0].asInt()); // blue channel
softPwmWrite(21, param[1].asInt()); // green channel
softPwmWrite(22, param[2].asInt()); // red channel
}
  1. Save the file by pressing Ctrl + O, followed by Enter, followed by Ctrl + X.
  2. Build the C++ project by running the following command:
pi@raspberrypi:~/blynk-library/linux $ ./build.sh raspberry
  1. After building the project, run it using the following command with the auth token associated with your Blynk app:
pi@raspberrypi:~/blynk-library/linux $sudo ./blynk --token=ca7bed1c92214503a65de8e20164994f
  1. With your Blynk app, tap the play button on the toolbar. The app will go to play mode:
zeRGBa widget in play mode
  1. Tap the zebra image to select a color. When you stop touching the screen, the LED will change to the color you selected. Note that the values for red, green, and blue change according to the different selections. Any time you want, you can quickly change the color to white by tapping the white circle in the upper-left corner of the widget, and to black by tapping anywhere on the background of the widget.

Listing 3.3 shows the source code for main.cpp:

Listing 3.3: Controlling RGB LED with zeRGBa

//#define BLYNK_DEBUG

#define BLYNK_PRINT stdout

#ifdef RASPBERRY

#include <BlynkApiWiringPi.h>

#else

#include <BlynkApiLinux.h>

#endif

#include <BlynkSocket.h>

#include <BlynkOptionsParser.h>

#include <wiringPi.h>

#include <softPwm.h>

static BlynkTransportSocket _blynkTransport;

BlynkSocket Blynk(_blynkTransport);

static const char *auth, *serv;

static uint16_t port;

#include <BlynkWidgets.h>

BLYNK_WRITE(V1)

{

printf("Got a value: %sn", param[0].asStr());

printf("Got a value: %sn", param[1].asStr());

printf("Got a value: %sn", param[2].asStr());

softPwmWrite(3, param[0].asInt());

softPwmWrite(21, param[1].asInt());

softPwmWrite(22, param[2].asInt());

}

void setup()

{

Blynk.begin(auth, serv, port);

softPwmCreate(3,0,255);

softPwmCreate(21,0,255);

softPwmCreate(22,0,255);

}

void loop()

{

Blynk.run();

}

intmain(intargc, char* argv[])

{

parse_options(argc, argv, auth, serv, port);

setup();

while(true) {

loop();

}

return 0;

}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.219.236.62