Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <WiFi.h>
- #include <FastLED.h>
- #include "Countimer.h"
- const char* ssid = "Clock_By_Grubits_Gabor";
- const char* password = "Clock2018#";
- WiFiServer server(80);
- String perc1, perc2, masod1, masod2, ido, header;
- int tomb[4];
- uint8_t colorIndex;
- #define NUM_LEDS 86
- #define DATA_PIN 4
- #define BRIGHTNESS 128
- CRGB LEDs[NUM_LEDS];
- CRGB colorCRGB = CRGB::Blue;
- CHSV colorCHSV = CHSV(0, 165, 255);
- CRGB colorOFF = CRGB(0, 0, 0);
- volatile int colorMODE = 0;
- Countimer tDown; //Work timer
- Countimer tDown2; //Pause timer
- int pausemin = 0;
- int pausesec = 10;
- int workmin = 0;
- int worksec = 20;
- int retry = 16;
- String workminstring = String(workmin);
- String worksecstring = String(worksec);
- void setup() {
- pinMode(2, OUTPUT);
- Serial.begin(115200);
- FastLED.delay(500);
- FastLED.addLeds<WS2812B, DATA_PIN, GRB>(LEDs, NUM_LEDS);
- FastLED.setBrightness(BRIGHTNESS);
- WiFi.softAP(ssid, password);
- //Serial.print("AP IP address: ");
- server.begin();
- tDown.setInterval(print_time1, 1000);
- tDown2.setInterval(print_time2, 1000);
- for (int z = 0; z < 1024; z++)
- {
- static uint8_t colorIndex = 0;
- colorIndex = colorIndex + 1;
- uint8_t brightness = 255;
- for ( int i = 0; i < NUM_LEDS; i++) {
- LEDs[i] = ColorFromPalette( RainbowColors_p, colorIndex, brightness, LINEARBLEND);
- colorIndex += 3;
- }
- FastLED.show();
- FastLED.delay(7);
- }
- //Serial.println(WiFi.softAPIP());
- ido = "00:00:20";
- tDown.setCounter(0, workmin, worksec, tDown.COUNT_DOWN, tDownComplete);
- tDown2.setCounter(0, pausemin, pausesec, tDown2.COUNT_DOWN, tDown2Complete);
- displayClock();
- }
- void loop() {
- tDown.run();
- tDown2.run();
- WiFiClient client = server.available();
- char clientline[BUFSIZ];
- int index = 0;
- if (client) {
- boolean currentLineIsBlank = true;
- boolean currentLineIsGet = true;
- int tCount = 0;
- char tBuf[64];
- char *pch;
- //Serial.print("Client request: ");
- while (client.connected()) {
- while (client.available()) {
- char c = client.read();
- header += c;
- if (currentLineIsGet && tCount < 63)
- {
- tBuf[tCount] = c;
- tCount++;
- tBuf[tCount] = 0;
- }
- if (c == '\n' && currentLineIsBlank) {
- while (client.available()) client.read();
- pch = strtok(tBuf, "?");
- while (pch != NULL)
- {
- if (strncmp(pch, "workmin=", 8) == 0)
- {
- workmin = atoi(pch + 8);
- if (workmin > 60) {
- workmin = 59;
- }
- if (worksec > 60) {
- worksec = 59;
- }
- tDown.setCounter(0, workmin, worksec, tDown.COUNT_DOWN, tDownComplete);
- }
- if (strncmp(pch, "worksec=", 8) == 0)
- {
- worksec = atoi(pch + 8);
- if (workmin > 60) {
- workmin = 59;
- }
- if (worksec > 60) {
- worksec = 60;
- }
- tDown.setCounter(0, workmin, worksec, tDown.COUNT_DOWN, tDownComplete);
- String worksecstring = String(worksec);
- String workminstring = String(workmin);
- if (worksec < 10) {
- worksecstring = "0" + worksecstring;
- }
- if (workmin < 10) {
- workminstring = "0" + workminstring;
- }
- ido = "00:" + workminstring + ":" + worksecstring;
- displayClock();
- }
- if (strncmp(pch, "pausemin=", 9) == 0)
- {
- pausemin = atoi(pch + 9);
- tDown2.setCounter(0, pausemin, pausesec, tDown2.COUNT_DOWN, tDown2Complete);
- }
- if (strncmp(pch, "pausesec=", 9) == 0)
- {
- pausesec = atoi(pch + 9);
- tDown2.setCounter(0, pausemin, pausesec, tDown2.COUNT_DOWN, tDown2Complete);
- if (pausesec > 60) {
- pausesec = 60;
- }
- if (pausemin > 60) {
- pausemin = 59;
- }
- }
- if (strncmp(pch, "retry=", 6) == 0)
- {
- retry = atoi(pch + 6);
- }
- pch = strtok(NULL, "& ");
- }
- if (header.indexOf("GET /start") >= 0) {
- tDown.start();
- tDown2.stop();
- } else if (header.indexOf("GET /stop") >= 0) {
- tDown.stop();
- tDown2.stop();
- } else if (header.indexOf("GET /pihi") >= 0) {
- tDown.pause();
- }
- client.print("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n<html><body><H1>TIMER</H1><form method=GET>");
- client.print("Work: <input type=text name=workmin value=");
- client.print(workmin);
- client.print(">min.<input type=text name=worksec value=");
- client.print(worksec);
- client.print(">sec.<br><br>");
- client.print("Pause:<input type=text name=pausemin value=");
- client.print(pausemin);
- client.print(">min.<input type=text name=pausesec value=");
- client.print(pausesec);
- client.print(">sec.<br><br>");
- client.print("Retry: <input type=text name=retry value=");
- client.print(retry);
- client.print("><br><input type=submit></form>");
- client.println("<!DOCTYPE html><html>");
- client.println("<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">");
- client.println("<link rel=\"icon\" href=\"data:,\">");
- client.println("<style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}");
- client.println(".button { background-color: #4CAF50; border: none; color: white; padding: 8px 20px;");
- client.println("text-decoration: none; font-size: 15px; margin: 2px; cursor: pointer;}");
- client.println(".button2 {background-color: #555555;}</style></head>");
- client.println("<body><h1>Control buttons</h1>");
- client.println("<p><a href=\"/start\"><button class=\"button button2\">RE/START</button></a></p>");
- client.println("<p><a href=\"/stop\"><button class=\"button button2\">STOP</button></a></p>");
- client.println("<p><a href=\"/pihi\"><button class=\"button button2\">PAUSE</button></a></p>");
- client.write("</body></html>\r\n\r\n");
- header = "";
- client.stop();
- }
- else if (c == '\n') {
- currentLineIsBlank = true;
- currentLineIsGet = false;
- }
- else if (c != '\r') {
- currentLineIsBlank = false;
- }
- }
- }
- }
- }
- void displayClock() {
- perc1 = (ido.substring(3, 4));
- perc2 = (ido.substring(4, 5));
- masod1 = (ido.substring(6, 7));
- masod2 = (ido.substring(7, 8));
- tomb[0] = perc1.toInt();
- tomb[1] = perc2.toInt();
- tomb[2] = masod1.toInt();
- tomb[3] = masod2.toInt();
- displaySegments(0, tomb[0]);
- displaySegments(21, tomb[1]);
- displaySegments(44, tomb[2]);
- displaySegments(65, tomb[3]);
- displayDots(0);
- FastLED.show();
- }
- void displayDots(int dotMode) {
- LEDs[42] = (LEDs[42] == colorOFF) ? (colorMODE == 0 ? colorCRGB : colorCHSV) : colorOFF;
- LEDs[43] = (LEDs[43] == colorOFF) ? (colorMODE == 0 ? colorCRGB : colorCHSV) : colorOFF;
- FastLED.show();
- }
- void displaySegments(int startindex, int number) {
- int numbers[] = {
- 0b0000111111111111111111, // 0
- 0b0000000000111111000000, // 1
- 0b0111000111111000111111, // 2
- 0b0111000111111111111000, // 3
- 0b0111111000111111000000, // 4
- 0b0111111111000111111000, // 5
- 0b0111111111000111111111, // 6
- 0b0000000111111111000000, // 7
- 0b0111111111111111111111, // 8
- 0b0111111111111111111000, // 9
- 0b0111111111111000000000, // ΒΊ 10
- 0b0000111111000000111111, // C(elcius) 11
- 0b0111000000000111111111, // ΒΊ lower 12
- 0b0000000000000000000000, // Empty 13
- 0b0111111111000000000111, // F(ahrenheit) 14
- };
- for (int i = 0; i < 21; i++) {
- LEDs[i + startindex] = ((numbers[number] & 1 << i) == 1 << i) ? (colorMODE == 0 ? colorCRGB : colorCHSV) : colorOFF;
- }
- }
- void tDownComplete()
- {
- tDown2.start();
- }
- void tDown2Complete()
- {
- if (retry > 1)
- {
- tDown.start();
- retry--;
- } else {
- digitalWrite(2, HIGH);
- for (int i = 0; i < 20; i++)
- {
- colorCRGB = CRGB::Red;
- displaySegments(0, 10);
- displaySegments(21, 12);
- displaySegments(44, 10);
- displaySegments(65, 12);
- displayDots(0);
- FastLED.show();
- FastLED.delay(200);
- colorCRGB = CRGB::White;
- displaySegments(0, 12);
- displaySegments(21, 10);
- displaySegments(44, 12);
- displaySegments(65, 10);
- displayDots(0);
- FastLED.show();
- FastLED.delay(200);
- }
- String worksecstring = String(worksec);
- String workminstring = String(workmin);
- if (worksec < 10) {
- worksecstring = "0" + worksecstring;
- }
- if (workmin < 10) {
- workminstring = "0" + workminstring;
- }
- colorCRGB = CRGB::Blue;
- ido = "00:" + workminstring + ":" + worksecstring;
- displayClock();
- digitalWrite(2, LOW);
- }
- }
- void print_time1()
- {
- colorCRGB = CRGB::Blue;
- ido = tDown.getCurrentTime();
- displayClock();
- }
- void print_time2()
- {
- colorCRGB = CRGB::Green;
- ido = tDown2.getCurrentTime();
- displayClock();
- }
Advertisement
Add Comment
Please, Sign In to add comment