#define BLYNK_TEMPLATE_ID "TMPL4n2YiDxo3"
#define BLYNK_TEMPLATE_NAME "Multiplication Glove"
#define BLYNK_AUTH_TOKEN "COeg84wDisGcS88rlmMLiXIe4O1p0-Rx"
#include <WiFi.h>
#include <WiFiClient.h>
// #include <espnow.h>
#include <BlynkSimpleEsp32.h>
#include <Arduino.h>
#include <Adafruit_NeoPixel.h>
#include <math.h>
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#define PINKY 27
#define RING 26
#define MIDDLE 25
#define INDEX 33
#define THUMB 32
#define NUM_PIXELS 5 // The number of LEDs (pixels) on WS2812C LED strip
char auth[] = BLYNK_AUTH_TOKEN;
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
int input1, input2;
Adafruit_NeoPixel pinkyFinger(NUM_PIXELS, PINKY, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel ringFinger(NUM_PIXELS, RING, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel middleFinger(NUM_PIXELS, MIDDLE, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel indexFinger(NUM_PIXELS, INDEX, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel thumbFinger(NUM_PIXELS, THUMB, NEO_GRB + NEO_KHZ800);
struct Adafruit_NeoPixel ledstrip[5] = { pinkyFinger, ringFinger, middleFinger, indexFinger, thumbFinger };
BLYNK_WRITE(V0)
{
input1 = param.asInt();
}
BLYNK_WRITE(V1)
{
input2 = param.asInt();
}
void setup() {
// Debug console
Serial.begin(115200);
pinMode (PINKY, OUTPUT);
pinMode (RING, OUTPUT);
pinMode (MIDDLE, OUTPUT);
pinMode (INDEX, OUTPUT);
pinMode (THUMB, OUTPUT);
pinkyFinger.begin(); // initialize WS2812C strip object (REQUIRED)
ringFinger.begin(); // initialize WS2812C strip object (REQUIRED)
middleFinger.begin(); // initialize WS2812C strip object (REQUIRED)
indexFinger.begin(); // initialize WS2812C strip object (REQUIRED)
thumbFinger.begin(); // initialize WS2812C strip object (REQUIRED)
Blynk.begin(auth, ssid, pass);
Blynk.syncVirtual(V0, V1);
}
void loop() {
Blynk.run();
pinkyFinger.clear(); // set all pixel colors to 'off'. It only takes effect if pixels.show() is called
ringFinger.clear(); // set all pixel colors to 'off'. It only takes effect if pixels.show() is called
middleFinger.clear(); // set all pixel colors to 'off'. It only takes effect if pixels.show() is called
indexFinger.clear(); // set all pixel colors to 'off'. It only takes effect if pixels.show() is called
thumbFinger.clear(); // set all pixel colors to 'off'. It only takes effect if pixels.show() is called
int x, y;
// multiplication of small numbers
while (input1 <= 5 || input2 <= 5) {
if (input1 <= input2) {
x = input2;
y = input1;
} else {
x = input1;
y = input2;
}
if (x > 5) {
x = 5;
}
if (y > 5) {
y = 5;
}
for (int i = 4; i >= x; i--) {
ledstrip[i].clear();
ledstrip[i].show(); // update to the WS2812C Led Strip
}
for (int i = 0; i < x; i++) {
for (int j = 0; j <= 4-y; j++) {
ledstrip[i].setPixelColor(j, ledstrip[i].Color(0, 0, 0)); // it only takes effect if pixels.show() is called
ledstrip[i].show();
}
}
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
ledstrip[i].setPixelColor(4-j, ledstrip[i].Color(0, 255, 0)); // it only takes effect if pixels.show() is called
ledstrip[i].show(); // update to the WS2812C Led Strip
delay(100); // 500ms pause between each pixel
}
}
Blynk.syncVirtual(V0, V1);
}
for (int i = 0; i <= 4; i++) {
ledstrip[i].clear();
ledstrip[i].show(); // update to the WS2812C Led Strip
}
//multiplication of big numbers
while (input1 > 5 && input2 > 5) {
for (int i = 4; i >= 10 - input1; i--) {
ledstrip[i].setPixelColor(4, ledstrip[i].Color(255, 0, 0)); // it only takes effect if pixels.show() is called
ledstrip[i].show(); // update to the WS2812C Led Strip
delay(100); // 500ms pause between each pixel
}
for (int i = 0; i < 10 - input1; i++) {
ledstrip[i].setPixelColor(4, ledstrip[i].Color(0, 0, 255)); // it only takes effect if pixels.show() is called
ledstrip[i].show(); // update to the WS2812C Led Strip
delay(100); // 500ms pause between each pixel
}
Blynk.syncVirtual(V0, V1);
}
}
Thumb
Index
Middle
Ring
Pinky