#include <Adafruit_GFX.h>
#include <Wire.h>
#include <U8g2lib.h>
U8G2_SSD1306_128X64_NONAME_F_HW_I2C pantasha(U8G2_R0);
const int sides = 35;
const int ups = 34;
const int switcher = 33;
const int speed = 32;
const int eraser = 4;
bool switchool = false;
bool changing = false;
bool block = true;
bool rasy = false;
int speedn = 1;
double hori = 64.0;
double verti = 32.0;
double tempo = 0;
std::vector<int> vtx;
std::vector<int> vty;
void switching() {
if (digitalRead(switcher) == HIGH && block == false) {
changing = !changing;
block = true;
}
if (millis() - tempo >= 30) {
tempo = millis();
if (digitalRead(switcher) == LOW && changing == false) {
switchool = true;
block = false;
}
else if (digitalRead(switcher) == LOW && changing == true) {
switchool = false;
block = false;
}
}
}
void motion(int ax, double &coor) {
if (analogRead(ax) > 2048) {
coor = coor + speedn;
}
else if (analogRead(ax) < 2048) {
coor = coor - speedn;
}
else {
coor = coor;
}
}
// formula: 10x/4096 - 5
void insertation() {
for (int i = 0; i <= vtx.size(); i++) {
pantasha.drawPixel(vtx[i], vty[i]);
}
}
void clearcond() {
}
void setup() {
pantasha.begin();
pinMode(switcher, INPUT_PULLUP);
pinMode(eraser, INPUT_PULLUP);
vtx.push_back(static_cast<int>(std::round(hori)));
vty.push_back(static_cast<int>(std::round(verti)));
pantasha.setFont(u8g2_font_helvR08_tf);
}
void loop() {
switching();
double speedr = analogRead(speed);
if (speedr <= 4095/5) {
speedn = 1;
}
else if (speedr <= 4095*2/5) {
speedn = 2;
}
else if (speedr <= 4095*3/5) {
speedn = 3;
}
else if (speedr <= 4095*4/5) {
speedn = 4;
}
else {
speedn = 5;
}
motion(sides, hori);
motion(ups, verti);
if (hori >= 122) {
hori = 122;
}
else if (hori <= 6) {
hori = 6;
}
if (verti >= 58) {
verti = 58;
}
else if (verti <= 6) {
verti = 6;
}
pantasha.clearBuffer();
pantasha.setDrawColor(1);
pantasha.drawCircle(int(hori), int(verti), 3);
insertation();
if (switchool == true) {
vtx.push_back(static_cast<int>(std::round(hori)));
vty.push_back(static_cast<int>(std::round(verti)));
}
// boton borrar boluo
const char* top = "You sure you";
const char* bottom = "wanna delete ALL?";
const char* ye = "yes";
const char* no = "no";
bool cajax = true;
if (digitalRead(eraser) == LOW) {
rasy = false;
while (rasy == false) {
pantasha.clearBuffer();
pantasha.drawStr((128 - pantasha.getStrWidth(top))/2, 20, top);
pantasha.drawStr((128 - pantasha.getStrWidth(bottom))/2, 35, bottom);
pantasha.drawStr((128 - pantasha.getStrWidth(ye))/3, 50, ye);
pantasha.drawStr((128 - pantasha.getStrWidth(no))*2/3, 50, no);
if (analogRead(sides) < 2048) {
cajax = true;
}
else if (analogRead(sides) > 2048) {
cajax = false;
}
if (cajax == true) {
pantasha.drawFrame((128 - pantasha.getStrWidth(ye))/3 - 1, 50 - 9, pantasha.getStrWidth(ye)+2, 10);
}
if (cajax == false) {
pantasha.drawFrame((128 - pantasha.getStrWidth(no))*2/3 - 1, 50 - 9, pantasha.getStrWidth(no)+2, 10);
}
if (cajax == true && digitalRead(switcher) == LOW) {
pantasha.clear();
rasy = true;
}
else if (cajax == false && digitalRead(switcher) == LOW) {
rasy = true;
}
else {
pantasha.sendBuffer();
}
}
}
pantasha.sendBuffer();
delay(20);
}Loading
esp32-devkit-c-v4
esp32-devkit-c-v4
Loading
ssd1306
ssd1306