Can someone help me with my code?

I’m relatively new to Arduino. I backed Blynk because I thought it would help me create things without having to know how to program from scratch. Well, at least that’s what I hoped.

I’ve been digging into this project for several months now. I’m trying to do something that I think should be simple but I’m just not having a easy time creating it. I have a lamp I 3d printed that uses a Cold Cathode Tube from a flat bed scanner as the light source. It runs off 12V and pulls 200ma when it is on. I put a mechanical switch on the front of my lamp. I plan to power this off of USB with a voltage booster to drive the lamp and a relay to turn that voltage on/off using an ESP8266 running Blynk and my code.

To start off I’m trying to just sort out my basic code to get the lamp to respond from two switches like a 3-way switch in a home. I want blank to be one of these switches and the mechanical switch to be the other. For testing I’m using two switches on a breadboard without using Blynk yet. I haven’t been able to get to that point. Ugh. I started with a bunch of if/else statements then came across the boolean. My code now uses the boolean. When I uploaded it to my board the LED I’m using in place of the relay just blinks(not to be confused with Blynk, LOL). I was expecting it to be off, then if I switched either switch to turn on and off again with the change in state of either switch. I hope that explains the project. Here is the code I have so far. Any help is much appreciated! -Tim-

    int LEDpin = 6;       // LED on pin 5
    int switchPin = 5;   // momentary switch on 5, other side connected to ground
    int digitalPin = 4;   // Blynk switch on pin 4
    int switchState = 0;  //previous state of switch
    int blynkState = 0;  //previous state of Blynk
    
    boolean isOn = false;
    
    void setup()
    {
      pinMode(LEDpin, OUTPUT);
      pinMode(switchPin, INPUT);
      pinMode(digitalPin, INPUT);
      Serial.begin(9600);
      
      digitalWrite(switchPin, LOW);      // turn on pullup resistor
    }
    
    void loop() 
    {
      //read the switch states
      switchState = digitalRead(switchPin);
      blynkState = digitalRead(digitalPin);
      //compaire both switches
      if (switchPin != switchState || blynkState != digitalPin) {
        if (switchPin == HIGH) {
        digitalWrite(digitalPin, HIGH);
        digitalWrite(blynkState, HIGH);
        }
        if (digitalPin == HIGH) {
        digitalWrite(switchPin, HIGH);
        digitalWrite(blynkState, HIGH);
        }
        if (switchPin == LOW) {
        digitalWrite(digitalPin, LOW);
        digitalWrite(blynkState, LOW);
        }
        if (digitalPin == LOW) {
        digitalWrite(switchPin, LOW);
        digitalWrite(blynkState, LOW);
    }else
        {  // switch has changed state
        delay(100);                        // delay to debounce switch
        isOn = !isOn;                // toggle lamp on/off
        digitalWrite(LEDpin, isOn);      // indicate via LED
      }
    }

Please:

  1. Post to related category: http://community.blynk.cc/c/projecthelp
  2. Make code readable by using </> button

Then you’ll have more chances to get a reply

I would suggest you use the switch() statement to make this happen in a good way. It should be much easier.

    switch(varName)
    { 
     case 1:
        //do something in case varName = 1
        break;
      case 2:
        //do something if varName = 2
       break;
     default:
        //do something if nothing matches varName
      break;
    }

This will at least make it more logical and readable I think.

1 Like

I moved this topic. I tried using the </> but I don’t think it worked as intended. Sorry Pavel.

I also changed the code to the latest version I’ve got so far. I’ll look into the switch command and see where that gets me. Thank you for the input Lichtsignaal.

I did it for you this time. Next time: select the code and press "</> " button

1 Like

OK, I gave this more thought today. It seems you can do this much easier if you think about the switches as a group. If both are in one state then the lamp should be off. If the switches are in different states then the lamp should be on. Given that, I wrote the following code. Everything verifies but when I actually load it to my board and wire up two switches and monitor the serial port all I see is LED off yet the LED I have wired up stays on. I even changed the pin to 13 to test the board’s LED. I then tried running the pin off ground instead of VCC. For some reason the board is not responding to the switches. I’d like it if someone with more experience with this could just look over this and maybe you see something I don’t, maybe even upload it to a board and see if you get the same thing? As soon as this is done I’m going to incorporate Blynk into this and finally try to load it up to an ESP8266. Thanks again.

    const int LED_PIN = 6;    // the pin that the pushbutton is attached to
    const int SWITCH_PIN = 5;       // the pin that the LED is attached to
    const int BLYNK_PIN = 4;   //the pin that the blynk app will use

    void setup() {
      //initialize the switch pin as an input:
      pinMode(SWITCH_PIN, INPUT);
      // initialize the LED as an output:
      pinMode(LED_PIN, OUTPUT);
      // initialize the blynk app as input:
      pinMode(BLYNK_PIN, INPUT);
      // initialize serial communication:
       Serial.begin(9600);
    }

    void loop() {
    //delay to debounce switch:
    delay(100);
    //compare both states:
    if (digitalRead(SWITCH_PIN) == digitalRead(BLYNK_PIN)) {
      digitalWrite(LED_PIN, LOW);
      Serial.println("LED off"); 
    }
    else
    {
     digitalWrite(LED_PIN, HIGH);
     Serial.println("LED on");
     }
    }

Update,

This code works. I had my switch wired up wrong. Now I need to figure out this ESP8266. Does this use the same pin numbers as arduino in arduino IDE or do I need to use GPI numbers? The example code I’ve seen for this board looks different than arduino but similar. I’ve been able to upload LUA firmware to the ESP but arduino doesn’t like it. I must have library issues I need to figure out.

Have a look here

Thanks for sharing that. I have looked over it. I’ve got the ESP working with that sample code. I’m going over the integration of Blynk now. I’m having a hard time figuring out how to monitor the state of the mechanical switch and the blynk switch widget. I also added an LED display widget to the blynk app that should display the status of the lamp (on or off).

I’m not sure of the best way to compare both switches. The Blynk app won’t be on all the time so the last signal it sends needs to be remembered and rewritten to the app switch when it restarts. I also need to read that state of the lamp on restart since it could have changed. So, I’m not reading over and over the GitHub trying to figure out how to use Blynk.virtualWrite and Blynk.virtualRead and BLYNK_READ and BLYNK_WRITE. I’m guessing BLYNK_READ and WRITE are constants since they are in all caps but like I said, I’m still trying to figure all of this out.

Here’s my attempt to incorporate Blynk. It doesn’t work. What am I doing wrong?:

    #define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
    #include <ESP8266WiFi.h>
    #include <BlynkSimpleEsp8266.h>
    
    char auth[] = "34c499cba10046a38045279e5b*******";


    const int LED_PIN = 2;    // the pin that the pushbutton is attached to
    const int SWITCH_PIN = 0;       // the pin that the LED is attached to
    //const int BLYNK_PIN = 5 ;   //the VIRTUAL pin that the blynk app will use

    void setup() 
    {
      Blynk.begin(auth, "******", "**********");
      pinMode(SWITCH_PIN, INPUT);
      // initialize the LED as an output:
      pinMode(LED_PIN, OUTPUT);
      // initialize serial communication:
      Serial.begin(9600);
    }
  
    void loop() {
      Blynk.run();
    //compare both states:
    delay(100);

    if (digitalRead(SWITCH_PIN) == BLYNK_READ(5)) {
      digitalWrite(LED_PIN, LOW);
      Serial.println("LED off");
    }
    else
    {
      digitalWrite(LED_PIN, HIGH);
      Serial.println("LED on");
     }
    }

I’m getting these errors. It almost seems like they are errors in the Blynk library:

In file included from /Users/twofieros/Documents/Arduino/libraries/blynk-library-master/Blynk/BlynkApi.h:17:0,
from /Users/twofieros/Documents/Arduino/libraries/blynk-library-master/BlynkApiArduino.h:14,
from /Users/twofieros/Documents/Arduino/libraries/blynk-library-master/BlynkSimpleEsp8266.h:18,
from lamp_test_6.ino:3:
lamp_test_6.ino: In function ‘void loop()’:
/Users/twofieros/Documents/Arduino/libraries/blynk-library-master/Blynk/BlynkHandlers.h:31:5: error: expected primary-expression before ‘void’
void BlynkWidgetRead ## pin (BlynkReq& request)
^
lamp_test_6.ino:27:32: note: in expansion of macro ‘BLYNK_READ’
/Users/twofieros/Documents/Arduino/libraries/blynk-library-master/Blynk/BlynkHandlers.h:31:5: error: expected ‘)’ before ‘void’
void BlynkWidgetRead ## pin (BlynkReq& request)
^
lamp_test_6.ino:27:32: note: in expansion of macro ‘BLYNK_READ’
In file included from /Users/twofieros/Documents/Arduino/libraries/blynk-library-master/BlynkSimpleEsp8266.h:18:0,
from lamp_test_6.ino:3:
/Users/twofieros/Documents/Arduino/libraries/blynk-library-master/BlynkApiArduino.h: At global scope:
/Users/twofieros/Documents/Arduino/libraries/blynk-library-master/BlynkApiArduino.h:44:6: warning: always_inline function might not be inlinable [-Wattributes]
void BlynkApi::processCmd(const void* buff, size_t len)
^
In file included from /Users/twofieros/Documents/Arduino/libraries/blynk-library-master/BlynkSimpleEsp8266.h:19:0,
from lamp_test_6.ino:3:
/Users/twofieros/Documents/Arduino/libraries/blynk-library-master/Blynk/BlynkProtocol.h:169:6: warning: always_inline function might not be inlinable [-Wattributes]
bool BlynkProtocol::processInput(void)
^
Multiple libraries were found for “BlynkSimpleEsp8266.h”
Used: /Users/twofieros/Documents/Arduino/libraries/blynk-library-master
Not used: /Applications/Arduino-2.app/Contents/Java/libraries/blynk-library-master
Error compiling.

You are overthinking :wink:
No fancy code is needed to control physical pins directly. Just Blynk.run();
Check the BlynkBlink example

Check other examples: GetData, PushData to understand how Virtual Pins work.

I think the delay function isn’t good using with blynk, you must do other tipes of delay like sipletimer.h library.
You have on codebender site very good blynk examples, just search for blynk.

1 Like

It seems there might be an issue with blynk’s library. I’m getting this error:
In file included from lamp_test_6.ino:5:0:
/Users/twofieros/Documents/Arduino/libraries/SPI/SPI.h:16:26: fatal error: avr/pgmspace.h: No such file or directory
#include <avr/pgmspace.h>
^
compilation terminated.

When I look into SPI.h is calls for avr/pgmspace.h but from what I can find online Arduino IDE doesn’t use that anymore. I cannot for the life of me figure out where to find a copy of it and add it. Perhaps that isn’t the best way to fix this. This is the only error I get on my program now.

Even if I open ESP8266_Shield and try to compile that I get this error:
Build options changed, rebuilding all
In file included from ESP8266_Shield.ino:42:0:
/Users/twofieros/Documents/Arduino/libraries/blynk-library-master/BlynkSimpleShieldEsp8266.h:21:21: fatal error: ESP8266.h: No such file or directory
#include <ESP8266.h>
^
compilation terminated.
Error compiling.

This indicates that the Blynk library isn’t complete. Is that right? Am I missing something?

The ESP8266_Shield example needs an additional library, have a look at the comments for details. If you paste the code for lamp_test_6.ino then I can see what I get on my computer. The ESP8266_Standalone example should compile okay.

No sure which Arduino / board you are using to control the ESP, but from your description of the project you can probably just use an ESP in which case you would look at ESP8266_Standalone rather than ESP8266_Shield. Can you describe the electronics as well as the code?

I got the ESP8266 to work with Blynk and I got it to flash an LED for me so I can load to the board and get it working. It’s just getting my code to work with Blynk has me stumped.

Thank you for looking into this for me.

The code is designed to compare the state of the Blynk switch and a mechanical switch on the lamp. If the states are the same the lamp will be off, if different the lamp should be on. I plan to power the lamp through a 2.1A USB cable. The 5V will be converted to 3.3V for the ESP and also boosted to 12V for the lamp power supply. The 12V will be triggered through a relay controlled by one pin on the ESP8266-01. The other pin will be used for the switch.

Once I have this working I hope to incorporate more devices with this setup and eventually hook up most light switches in my house with it. I hope that explains it for you.

1 Like

Can anyone else get the example code ButtonInterrupt to compile?

You need latest Arduino IDE in order to compile that example.

I’m using 1.6.5 which is the latest but it won’t compile. perhaps this is why I’m having trouble with compiling my own code. Today I uninstalled and reinstalled arduino in hopes it would resolve the issue but I’m getting the same errors.

This is what I get when I try to compile ButtonInterrupt:
In file included from /Users/twofieros/Documents/Arduino/libraries/blynk-library-master/Adapters/BlynkEthernet.h:18:0,
from /Users/twofieros/Documents/Arduino/libraries/blynk-library-master/BlynkSimpleEthernet.h:20,
from ButtonInterrupt.ino:27:
/Users/twofieros/Documents/Arduino/libraries/blynk-library-master/BlynkApiArduino.h:50:6: warning: always_inline function might not be inlinable [-Wattributes]
void BlynkApi::processCmd(const void* buff, size_t len)
^
In file included from /Users/twofieros/Documents/Arduino/libraries/blynk-library-master/Adapters/BlynkEthernet.h:19:0,
from /Users/twofieros/Documents/Arduino/libraries/blynk-library-master/BlynkSimpleEthernet.h:20,
from ButtonInterrupt.ino:27:
/Users/twofieros/Documents/Arduino/libraries/blynk-library-master/Blynk/BlynkProtocol.h:200:6: warning: always_inline function might not be inlinable [-Wattributes]
bool BlynkProtocol::processInput(void)
^
/Applications/Arduino-2.app/Contents/Java/libraries/Ethernet/src/Ethernet.cpp: In member function ‘int EthernetClass::begin(uint8_t*)’:
/Applications/Arduino-2.app/Contents/Java/libraries/Ethernet/src/Ethernet.cpp:19:45: error: no matching function for call to ‘SPIClass::beginTransaction(int, SPISettings)’
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
^
/Applications/Arduino-2.app/Contents/Java/libraries/Ethernet/src/Ethernet.cpp:19:45: note: candidate is:
In file included from /Applications/Arduino-2.app/Contents/Java/libraries/Ethernet/src/utility/w5100.h:13:0,
from /Applications/Arduino-2.app/Contents/Java/libraries/Ethernet/src/Ethernet.cpp:1:
/Users/twofieros/Library/Arduino15/packages/esp8266/hardware/esp8266/1.6.5-947-g39819f0/libraries/SPI/SPI.h:63:8: note: void SPIClass::beginTransaction(SPISettings)
void beginTransaction(SPISettings settings);
^
/Users/twofieros/Library/Arduino15/packages/esp8266/hardware/esp8266/1.6.5-947-g39819f0/libraries/SPI/SPI.h:63:8: note: candidate expects 1 argument, 2 provided
/Applications/Arduino-2.app/Contents/Java/libraries/Ethernet/src/Ethernet.cpp:30:47: error: no matching function for call to ‘SPIClass::beginTransaction(int, SPISettings)’
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
^
/Applications/Arduino-2.app/Contents/Java/libraries/Ethernet/src/Ethernet.cpp:30:47: note: candidate is:
In file included from /Applications/Arduino-2.app/Contents/Java/libraries/Ethernet/src/utility/w5100.h:13:0,
from /Applications/Arduino-2.app/Contents/Java/libraries/Ethernet/src/Ethernet.cpp:1:
/Users/twofieros/Library/Arduino15/packages/esp8266/hardware/esp8266/1.6.5-947-g39819f0/libraries/SPI/SPI.h:63:8: note: void SPIClass::beginTransaction(SPISettings)
void beginTransaction(SPISettings settings);
^
/Users/twofieros/Library/Arduino15/packages/esp8266/hardware/esp8266/1.6.5-947-g39819f0/libraries/SPI/SPI.h:63:8: note: candidate expects 1 argument, 2 provided
/Applications/Arduino-2.app/Contents/Java/libraries/Ethernet/src/Ethernet.cpp: In member function ‘void EthernetClass::begin(uint8_t*, IPAddress, IPAddress, IPAddress, IPAddress)’:
/Applications/Arduino-2.app/Contents/Java/libraries/Ethernet/src/Ethernet.cpp:68:45: error: no matching function for call to ‘SPIClass::beginTransaction(int, SPISettings)’
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
^
/Applications/Arduino-2.app/Contents/Java/libraries/Ethernet/src/Ethernet.cpp:68:45: note: candidate is:
In file included from /Applications/Arduino-2.app/Contents/Java/libraries/Ethernet/src/utility/w5100.h:13:0,
from /Applications/Arduino-2.app/Contents/Java/libraries/Ethernet/src/Ethernet.cpp:1:
/Users/twofieros/Library/Arduino15/packages/esp8266/hardware/esp8266/1.6.5-947-g39819f0/libraries/SPI/SPI.h:63:8: note: void SPIClass::beginTransaction(SPISettings)
void beginTransaction(SPISettings settings);
^
/Users/twofieros/Library/Arduino15/packages/esp8266/hardware/esp8266/1.6.5-947-g39819f0/libraries/SPI/SPI.h:63:8: note: candidate expects 1 argument, 2 provided
/Applications/Arduino-2.app/Contents/Java/libraries/Ethernet/src/Ethernet.cpp: In member function ‘int EthernetClass::maintain()’:
/Applications/Arduino-2.app/Contents/Java/libraries/Ethernet/src/Ethernet.cpp:89:51: error: no matching function for call to ‘SPIClass::beginTransaction(int, SPISettings)’
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
^
/Applications/Arduino-2.app/Contents/Java/libraries/Ethernet/src/Ethernet.cpp:89:51: note: candidate is:
In file included from /Applications/Arduino-2.app/Contents/Java/libraries/Ethernet/src/utility/w5100.h:13:0,
from /Applications/Arduino-2.app/Contents/Java/libraries/Ethernet/src/Ethernet.cpp:1:
/Users/twofieros/Library/Arduino15/packages/esp8266/hardware/esp8266/1.6.5-947-g39819f0/libraries/SPI/SPI.h:63:8: note: void SPIClass::beginTransaction(SPISettings)
void beginTransaction(SPISettings settings);
^
/Users/twofieros/Library/Arduino15/packages/esp8266/hardware/esp8266/1.6.5-947-g39819f0/libraries/SPI/SPI.h:63:8: note: candidate expects 1 argument, 2 provided
/Applications/Arduino-2.app/Contents/Java/libraries/Ethernet/src/Ethernet.cpp: In member function ‘IPAddress EthernetClass::localIP()’:
/Applications/Arduino-2.app/Contents/Java/libraries/Ethernet/src/Ethernet.cpp:107:45: error: no matching function for call to ‘SPIClass::beginTransaction(int, SPISettings)’
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
^
/Applications/Arduino-2.app/Contents/Java/libraries/Ethernet/src/Ethernet.cpp:107:45: note: candidate is:
In file included from /Applications/Arduino-2.app/Contents/Java/libraries/Ethernet/src/utility/w5100.h:13:0,
from /Applications/Arduino-2.app/Contents/Java/libraries/Ethernet/src/Ethernet.cpp:1:
/Users/twofieros/Library/Arduino15/packages/esp8266/hardware/esp8266/1.6.5-947-g39819f0/libraries/SPI/SPI.h:63:8: note: void SPIClass::beginTransaction(SPISettings)
void beginTransaction(SPISettings settings);
^
/Users/twofieros/Library/Arduino15/packages/esp8266/hardware/esp8266/1.6.5-947-g39819f0/libraries/SPI/SPI.h:63:8: note: candidate expects 1 argument, 2 provided
/Applications/Arduino-2.app/Contents/Java/libraries/Ethernet/src/Ethernet.cpp: In member function ‘IPAddress EthernetClass::subnetMask()’:
/Applications/Arduino-2.app/Contents/Java/libraries/Ethernet/src/Ethernet.cpp:116:45: error: no matching function for call to ‘SPIClass::beginTransaction(int, SPISettings)’
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
^
/Applications/Arduino-2.app/Contents/Java/libraries/Ethernet/src/Ethernet.cpp:116:45: note: candidate is:
In file included from /Applications/Arduino-2.app/Contents/Java/libraries/Ethernet/src/utility/w5100.h:13:0,
from /Applications/Arduino-2.app/Contents/Java/libraries/Ethernet/src/Ethernet.cpp:1:
/Users/twofieros/Library/Arduino15/packages/esp8266/hardware/esp8266/1.6.5-947-g39819f0/libraries/SPI/SPI.h:63:8: note: void SPIClass::beginTransaction(SPISettings)
void beginTransaction(SPISettings settings);
^
/Users/twofieros/Library/Arduino15/packages/esp8266/hardware/esp8266/1.6.5-947-g39819f0/libraries/SPI/SPI.h:63:8: note: candidate expects 1 argument, 2 provided
/Applications/Arduino-2.app/Contents/Java/libraries/Ethernet/src/Ethernet.cpp: In member function ‘IPAddress EthernetClass::gatewayIP()’:
/Applications/Arduino-2.app/Contents/Java/libraries/Ethernet/src/Ethernet.cpp:125:45: error: no matching function for call to ‘SPIClass::beginTransaction(int, SPISettings)’
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
^
/Applications/Arduino-2.app/Contents/Java/libraries/Ethernet/src/Ethernet.cpp:125:45: note: candidate is:
In file included from /Applications/Arduino-2.app/Contents/Java/libraries/Ethernet/src/utility/w5100.h:13:0,
from /Applications/Arduino-2.app/Contents/Java/libraries/Ethernet/src/Ethernet.cpp:1:
/Users/twofieros/Library/Arduino15/packages/esp8266/hardware/esp8266/1.6.5-947-g39819f0/libraries/SPI/SPI.h:63:8: note: void SPIClass::beginTransaction(SPISettings)
void beginTransaction(SPISettings settings);
^
/Users/twofieros/Library/Arduino15/packages/esp8266/hardware/esp8266/1.6.5-947-g39819f0/libraries/SPI/SPI.h:63:8: note: candidate expects 1 argument, 2 provided
Error compiling.
java.net.SocketException: Can’t assign requested address
at java.net.PlainDatagramSocketImpl.join(Native Method)
at java.net.AbstractPlainDatagramSocketImpl.join(AbstractPlainDatagramSocketImpl.java:179)
at java.net.MulticastSocket.joinGroup(MulticastSocket.java:323)
at javax.jmdns.impl.JmDNSImpl.openMulticastSocket(JmDNSImpl.java:463)
at javax.jmdns.impl.JmDNSImpl.(JmDNSImpl.java:420)
at javax.jmdns.JmDNS.create(JmDNS.java:81)
at cc.arduino.packages.discoverers.NetworkDiscovery.inetAddressAdded(NetworkDiscovery.java:192)
at cc.arduino.packages.discoverers.network.NetworkChecker.run(NetworkChecker.java:62)
at java.util.TimerThread.mainLoop(Timer.java:555)
at java.util.TimerThread.run(Timer.java:505)

I have not given up yet but I’m getting close to it. I still cannot figure out how to pull the value of a virtual pin. I’ve look at GetData, PushData and all the sample codes. Here’s what I have now:

    #define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
    #include <ESP8266WiFi.h>
    #include <BlynkSimpleEsp8266.h>
    
    
    char auth[] = "34c*************3";
    
    
    const int LED_PIN = 2;    // the pin that the pushbutton is attached to
    const int SWITCH_PIN = 0;       // the pin that the LED is attached to
    
    void setup() 
    {
      Blynk.begin(auth, "P**e", "t****s");
      pinMode(SWITCH_PIN, INPUT);
      // initialize the LED as an output:
      pinMode(LED_PIN, OUTPUT);
      // initialize serial communication:
      Serial.begin(9600);
    }
    // This function will be called every time
    // when App writes value to Virtual Pin 1
    BLYNK_WRITE(1)
    {
      BLYNK_LOG("Got a value: %s", param.asInt());
      // You can also use: asInt() and asDouble()
    }
    
    void loop() {
      Blynk.run();
    //compare both states:
    if (digitalRead(SWITCH_PIN) == BLYNK_READ(1)) {
      digitalWrite(LED_PIN, LOW);
      Serial.println("LED off");
    }
    else
    {
      digitalWrite(LED_PIN, HIGH);
      Serial.println("LED on");
     }
    }

Could someone please explain how I can use the virtual pins? Layman terms please.