RaspberyPi JoyStick

I am using a raspberry pi and the Geany IDE to build the following Raspberry Pi sketch obtained from the Sketch builder examples,see below…

Blynk is a platform with iOS and Android apps to control
Arduino, Raspberry Pi and the likes over the Internet.
You can easily build graphic interfaces for all your
projects by simply dragging and dropping widgets.

Downloads, docs, tutorials: http://www.blynk.cc
Blynk community:            http://community.blynk.cc
Social networks:            http://www.fb.com/blynkapp

Blynk library is licensed under MIT license
This example code is in public domain.

You can receive x and y coords for joystick movement within App.

App project setup:
Two Axis Joystick on V1 in MERGE output mode.
MERGE mode means device will receive both x and y within 1 message

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT stdout

#include <BlynkApiWiringPi.h>
#include <BlynkApiLinux.h>
#include <BlynkSocket.h>
#include <BlynkOptionsParser.h>

static BlynkTransportSocket _blynkTransport;
BlynkSocket Blynk(_blynkTransport);
#include <BlynkWidgets.h>

int x = param[0].asInt();
int y = param[1].asInt();

// Do something with x and y
Serial.print("X = “);
Serial.print(”; Y = ");

void setup()

void loop()

int main(int argc, char* argv[])
const char *auth, *serv;
uint16_t port;
parse_options(argc, argv, auth, serv, port);

Blynk.begin(auth, serv, port);

while(true) {

return 0;

Please take a look at your post.

Terrible formatting, search the site on how to post a formatted sketch.

No question, do you think we are mind readers?

Sorry for the previous crappy post.
I am using a raspberry pi and the Geany IDE to build the following Raspberry Pi sketch obtained from the Sketch builder examples,see below.
When I try to build it the error message says cannot find BlynkApiWiringPi.
The project was placed however it the Blynk library where this “missing” file is located.
Any idea?
Thank you,

Take a look at this thread Using C++ on a Raspberry Pi with Blynk

Thank you, from the link you suggested I was able to read the joystick and display the results on my pi screen.
How would I modify the code in the link to get pwm to work on the pi?
So far,I’ve used the commands pinMode(1,PWM_OUTPUT) and pwmWrite(1,255) to output the pwm to pin1, gpio 18, on the pi to control an LED without luck, it did not light.

1 Like

@FizixDan we don’t use PWM as for us something is either on or off.

I suspect you know more than us about PWM and presumably you are familiar with Gordon (GPIO god) Henderson’s Software PWM for the PI at https://projects.drogon.net/raspberry-pi/wiringpi/software-pwm-library/

The following will pulse an LED from off, to full on and back down to off in a continuous loop.

#include <wiringPi.h>
#include <softPwm.h>

int bright;

int main (void)

wiringPiSetup () ;
softPwmCreate (7,0,100) ;  // wiringPi 7 (BCM 4) start at 0, maximum 100%

  for (;;)
    for (bright = 0 ; bright < 30 ; ++bright)
      softPwmWrite (7, bright) ;
      delay (50) ;
    for (bright = 29 ; bright >= 0 ; --bright)
      softPwmWrite (7, bright) ;
      delay (50) ;

Note even though this will pulse an LED from off to on it doesn’t cover the full pwm range. You would need to increase the 2 entries of 30 for this but it’s not required for an LED.

As a standalone test this can be compiled with:

cc -o myprog myprog.c -lwiringPi -lpthread
and run as:

-lwiringPi and -lpthread are covered when you use the build.sh script for Blynk so with a bit of effort you should be able to get something working with Blynk and Pi using C++.