For fast transaction call 0916.457.0748
Wemos D1 Switching Button with Display

Wemos D1 Switching Button with Display

 The D1 mini Pro is designed to allow Wemos compatible shields to be plugged into the board in a similar way to the Arduino development board platform which greatly expands its capabilities.

This tutorial, we'll be using two of the Wemos compatible shield. This include the 1-button shield and a OLED display.

Things you'll need:

  • Wemos D1 Mini
  • Wemos D1 Shield 1-Button
  • Wemos D1 Shield OLED
  • Wemos D1 Shield Dual Base

Building the Code:

Before you can upload the code to your Wemos.
Download and include first the following library:

Instruction here to install Wemos Board.
Please follow Installing with Boards Manager!

 #include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include "Adafruit_SSD1306.h"
#include "Switch.h"

#define OLED_RESET 0 // GPIO0
Adafruit_SSD1306 display(OLED_RESET);

const byte buttonPin = D3;

int i=0;

Switch button = Switch(buttonPin);

void setup() {
Serial.begin(115200);

pinMode(buttonPin, INPUT);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.display();
}

void loop() {
button.poll();

display.clearDisplay();
display.setTextSize(3);
display.setTextColor(WHITE);

if(button.pushed()){
Serial.println("Pressed!");
i++;
if(i == 1){onState();}
if(i == 2){offState(); i=0;}
}
}

void onState(){
display.setCursor(47,10);
display.print("ON");
display.display();
}

void offState(){
display.setCursor(40,10);
display.print("OFF");
display.display();
}

 

Copy code to your Arduino IDE.

Select Board: "Wemos D1 R2 & mini"

 Please take note of the following details:

 

Upload the code.
That's it!

 

Happy Coding!


0 comments

Leave a comment

Please note, comments must be approved before they are published

Payment Methods

Facebook Rewards Program