diff --git a/README.md b/README.md index 9f176a6..20c5ad7 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ # ArduinoLearningKitStarter-library -Library for DPS ArduinoLearningKitStarter from RobotikaBrno with definition of pins. +Library for PCB ArduinoLearningKitStarter from RobotikaBrno with definition of pins. -ArduinoLearningKitStarter DPS: https://github.com/RoboticsBrno/ArduinoLearningKitStarter/ \ No newline at end of file +ArduinoLearningKitStarter PCB: https://github.com/RoboticsBrno/ArduinoLearningKitStarter/ diff --git a/examples/boardTest/boardTest.ino b/examples/boardTest/boardTest.ino new file mode 100644 index 0000000..6786188 --- /dev/null +++ b/examples/boardTest/boardTest.ino @@ -0,0 +1,112 @@ +// Board tester firmare, remake by CornyjK. + +#include +#include + +#define DHTTYPE DHT11 + +DHT dht(DHT_PIN, DHTTYPE); + +/*int freq = 2000; + int channel = 0; + int resolution = 8;*/ + +unsigned long t_inc = 0; +unsigned long t_meas = 0; +uint8_t cnt = 0; + +void setup() { + setupAll(); + Serial.begin(DEFAULT_SERIAL_SPEED); + dht.begin(); + /*ledcSetup(channel, freq, resolution); + ledcAttachPin(19, channel);*/ + Serial.print("Arduino learning kit starter hardware test firmware\n"); +} + +void loop() { + if ((millis() - t_inc) >= 500) + { + t_inc = millis(); + ++cnt; + digitalWrite(L_R, cnt & 1 ? HIGH : LOW); + digitalWrite(L_Y, cnt & 2 ? HIGH : LOW); + digitalWrite(L_G, cnt & 4 ? HIGH : LOW); + digitalWrite(L_B, cnt & 8 ? HIGH : LOW); + } + + if ((millis() - t_meas) >= 500) + { + t_meas = millis(); + float t = dht.readTemperature(); + if (isnan(t)) + { + Serial.println("TEMPERATURE ERROR"); + } + else + { + Serial.print("Temperature: "); + Serial.print(int(t)); + } + Serial.print("\tlight: "); + Serial.print(analogRead(PHOTO)); + Serial.print("\tleft pot: "); + Serial.print(analogRead(POT1)); + Serial.print("\tright pot: "); + Serial.print(analogRead(POT2)); + Serial.print("\n"); + } + + digitalWrite(L_RGB_R, digitalRead(SW3) == HIGH ? LOW : HIGH); + digitalWrite(L_RGB_G, digitalRead(SW2) == HIGH ? LOW : HIGH); + digitalWrite(L_RGB_B, digitalRead(SW1) == HIGH ? LOW : HIGH); + + /*if (digitalRead(SW1) == LOW && digitalRead(SW2) == LOW) + { + digitalWrite(18, LOW); + Serial.write('PIEZO TEST! Alpha release, removed'); + cnt = 0; + digitalWrite(L_R , LOW); + digitalWrite(L_Y , LOW); + digitalWrite(L_G , LOW); + digitalWrite(L_B , LOW); + digitalWrite(L_RGB_R, LOW); + digitalWrite(L_RGB_G, LOW); + digitalWrite(L_RGB_B, LOW); + ledcWriteTone(channel, 2000); + + for (int dutyCycle = 0; dutyCycle <= 255; dutyCycle = dutyCycle + 10) { + + Serial.println(dutyCycle); + + ledcWrite(channel, dutyCycle); + delay(1000); + } + + ledcWrite(channel, 125); + + for (int freq = 255; freq < 10000; freq = freq + 250) { + + Serial.println(freq); + + ledcWriteTone(channel, freq); + delay(1000); + } + } + ledcWriteTone(channel, 0);*/ + + if (Serial.available()) + { + char c = Serial.read(); + switch (c) + { + case '\r': + Serial.write('\n'); + break; + default: + Serial.write(c + 1); + Serial.write('\n'); + break; + } + } +} diff --git a/examples/buttonSetLed/buttonSetLed.ino b/examples/buttonSetLed/buttonSetLed.ino index e87a83c..6b65cea 100644 --- a/examples/buttonSetLed/buttonSetLed.ino +++ b/examples/buttonSetLed/buttonSetLed.ino @@ -1,7 +1,6 @@ -#include "LearningKit.h" - +#include void setup() { - Serial.begin(115200); + Serial.begin(DEFAULT_SERIAL_SPEED); setupRgbLed(); setupLeds(); setupButtons(); @@ -16,4 +15,4 @@ void loop() { Serial.println("SW1 is press => RED light"); } delay(200); -} \ No newline at end of file +} diff --git a/examples/leds/leds.ino b/examples/leds/leds.ino index 7524691..4897bd2 100644 --- a/examples/leds/leds.ino +++ b/examples/leds/leds.ino @@ -1,7 +1,7 @@ -#include "LearningKit.h" +#include void setup() { - Serial.begin(115200); + Serial.begin(DEFAULT_SERIAL_SPEED); setupRgbLed(); setupLeds(); } @@ -43,4 +43,4 @@ void loop() { delay(500); digitalWrite(L_B, LOW); delay(500); -} \ No newline at end of file +} diff --git a/keywords.txt b/keywords.txt new file mode 100644 index 0000000..2126039 --- /dev/null +++ b/keywords.txt @@ -0,0 +1,19 @@ +########################################### +# Syntax Coloring Map For ALKS +########################################### + +########################################### +# Datatypes (KEYWORD1) +########################################### + +ALKS KEYWORD1 + +########################################### +# Methods and Functions (KEYWORD2) +########################################### + +setupLeds KEYWORD2 +setupRgbLed KEYWORD2 +setupButtons KEYWORD2 +setupPiezo() KEYWORD2 +setupAll() KEYWORD2 \ No newline at end of file diff --git a/library.json b/library.json index d5860e2..14d7614 100644 --- a/library.json +++ b/library.json @@ -9,10 +9,15 @@ }, "authors": [ { + "name": "Kryštof Černý", + "email": "cleverline1mc@gmail.com", + "url": "http://www.robotikabrno.cz", + "maintainer": true + }, + { "name": "Jan Mrázek", "email": "email@honzamrazek.cz", "url": "http://www.robotikabrno.cz", - "maintainer": true }, { "name": "Jaroslav Paral", @@ -20,7 +25,16 @@ "url": "http://www.robotikabrno.cz" } ], - "version": "1.0.2", + "version": "1.1.1", "frameworks": "arduino", - "platforms": "espressif32" + "platforms": "atmelavr, espressif32" + "dependencies": [ + { + "name": "ServoESP32", + "platforms": "espressif32" + } + { + "name": "DHT sensor library" + } + ] } \ No newline at end of file diff --git a/library.properties b/library.properties index be96369..d79f51b 100644 --- a/library.properties +++ b/library.properties @@ -1,9 +1,9 @@ name=ArduinoLearningKitStarter -version=1.0.2 +version=1.1.1 author=Jan Mrázek -maintainer=Jan Mrázek -sentence=Library for the ArduinoLearningKitStarter DPS by RobotikaBrno. +maintainer=Kryštof Černý +sentence=Library for the ArduinoLearningKitStarter PCB by RobotikaBrno. paragraph= category=Signal Input/Output url=https://github.com/RoboticsBrno/ArduinoLearningKitStarter-library.git -architectures=espressif32 \ No newline at end of file +architectures=avr, esp32 diff --git a/src/ALKS.cpp b/src/ALKS.cpp new file mode 100644 index 0000000..6290e33 --- /dev/null +++ b/src/ALKS.cpp @@ -0,0 +1,37 @@ +#include "ALKS.h" + +void setupLeds() +{ + pinMode(L_R, OUTPUT); + pinMode(L_G, OUTPUT); + pinMode(L_B, OUTPUT); + pinMode(L_Y, OUTPUT); +} + +void setupRgbLed() +{ + pinMode(L_RGB_R, OUTPUT); + pinMode(L_RGB_G, OUTPUT); + pinMode(L_RGB_B, OUTPUT); +} + +void setupButtons() +{ + pinMode(SW1, INPUT_PULLUP); + pinMode(SW2, INPUT_PULLUP); + pinMode(SW3, INPUT_PULLUP); +} + +void setupPiezo() +{ + pinMode(PIEZO1, OUTPUT); + pinMode(PIEZO2, OUTPUT); +} + +void setupAll() +{ + setupLeds(); + setupRgbLed(); + setupButtons(); + setupPiezo(); +} \ No newline at end of file diff --git a/src/ALKS.h b/src/ALKS.h new file mode 100644 index 0000000..b58473b --- /dev/null +++ b/src/ALKS.h @@ -0,0 +1,96 @@ +#pragma once + +#include "Arduino.h" + +static const uint32_t DEFAULT_SERIAL_SPEED = 115200; + +#ifdef LegALKS +static const uint8_t L_R = 12; +static const uint8_t L_G = 7; +static const uint8_t L_Y = 13; +static const uint8_t L_B = 8; +static const uint8_t L_RGB_R = 5; +static const uint8_t L_RGB_G = 11; +static const uint8_t L_RGB_B = 6; + +static const uint8_t SW1 = 2; +static const uint8_t SW2 = 4; +static const uint8_t SW3 = 3; + +static const uint8_t POT1 = A0; +static const uint8_t POT2 = A1; + +static const uint8_t PIEZO1 = 9; +static const uint8_t PIEZO2 = 10; + +static const uint8_t PHOTO = A2; + +static const uint8_t DHT_PIN = A3; + +#elif defined(AVR) +static const uint8_t L_R = 12; +static const uint8_t L_G = 7; +static const uint8_t L_Y = 13; +static const uint8_t L_B = 8; +static const uint8_t L_RGB_R = 5; +static const uint8_t L_RGB_G = 11; +static const uint8_t L_RGB_B = 6; + +static const uint8_t SW1 = 2; +static const uint8_t SW2 = 3; +static const uint8_t SW3 = 4; + +static const uint8_t POT1 = A0; +static const uint8_t POT2 = A1; + +static const uint8_t PIEZO1 = 9; +static const uint8_t PIEZO2 = 10; + +static const uint8_t PHOTO = A2; + +static const uint8_t DHT_PIN = A3; + +static const uint8_t S1 = 5; +static const uint8_t S2 = 6; +static const uint8_t S3 = 9; +static const uint8_t S4 = 10; +static const uint8_t S5 = 11; + +#elif defined(ESP32) +static const uint8_t L_R = 22; +static const uint8_t L_G = 17; +static const uint8_t L_Y = 23; +static const uint8_t L_B = 5; +static const uint8_t L_RGB_R = 4; +static const uint8_t L_RGB_G = 21; +static const uint8_t L_RGB_B = 16; + +static const uint8_t SW1 = 15; +static const uint8_t SW2 = 2; +static const uint8_t SW3 = 0; + +static const uint8_t POT1 = 32; +static const uint8_t POT2 = 33; + +static const uint8_t PIEZO1 = 19; +static const uint8_t PIEZO2 = 18; + +static const uint8_t PHOTO = 25; + +static const uint8_t DHT_PIN = 26; + +static const uint8_t S1 = 4; +static const uint8_t S2 = 16; +static const uint8_t S3 = 18; +static const uint8_t S4 = 19; +static const uint8_t S5 = 21; + +#else + #error "Selected unsupported platform/processor!" +#endif + +void setupLeds(); +void setupRgbLed(); +void setupButtons(); +void setupPiezo(); +void setupAll(); diff --git a/src/LearningKit.cpp b/src/LearningKit.cpp deleted file mode 100644 index 2f0548f..0000000 --- a/src/LearningKit.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include "LearningKit.h" - -void setupLeds() { - pinMode( L_R, OUTPUT ); - pinMode( L_G, OUTPUT ); - pinMode( L_B, OUTPUT ); - pinMode( L_Y, OUTPUT ); -} - -void setupRgbLed() { - pinMode( L_RGB_R, OUTPUT ); - pinMode( L_RGB_G, OUTPUT ); - pinMode( L_RGB_B, OUTPUT ); -} - -void setupButtons() { - pinMode( SW1, INPUT_PULLUP ); - pinMode( SW2, INPUT_PULLUP ); - pinMode( SW3, INPUT_PULLUP ); -} \ No newline at end of file diff --git a/src/LearningKit.h b/src/LearningKit.h index a154edd..084a84a 100644 --- a/src/LearningKit.h +++ b/src/LearningKit.h @@ -1,37 +1,2 @@ #pragma once - -#include "Arduino.h" - -static const int DEFAULT_SERIAL_SPEED = 115200; - -static const int L_R = 22; -static const int L_G = 17; -static const int L_Y = 23; -static const int L_B = 5; -static const int L_RGB_R = 4; -static const int L_RGB_G = 21; -static const int L_RGB_B = 16; - -static const int SW1 = 15; -static const int SW2 = 2; -static const int SW3 = 0; - -static const int POT1 = 32; -static const int POT2 = 33; - -static const int PIEZO1 = 19; -static const int PIEZO2 = 18; - -static const int PHOTO = 25; - -static const int DHT_PIN = 26; - -static const int S1 = 4; -static const int S2 = 16; -static const int S3 = 18; -static const int S4 = 19; -static const int S5 = 21; - -void setupLeds(); -void setupRgbLed(); -void setupButtons(); +#include "ALKS.h"