diff --git a/app/testdata/libraries/LiyabBasic/examples/Liyab_Knob.ino b/app/testdata/libraries/LiyabBasic/examples/Liyab_Knob.ino new file mode 100644 index 0000000000..2c2e3f6cec --- /dev/null +++ b/app/testdata/libraries/LiyabBasic/examples/Liyab_Knob.ino @@ -0,0 +1,15 @@ +/* Liyab Basic Microcontroller - Knob Calibration */ + +#include + +#define knob A2 + +void setup() { + Liyab_Init(); + OK(); +} + +void loop() { + int value = analogRead(knob); + Serial.println(value); +} diff --git a/app/testdata/libraries/LiyabBasic/examples/Liyab_Motors.ino b/app/testdata/libraries/LiyabBasic/examples/Liyab_Motors.ino new file mode 100644 index 0000000000..d2e8412131 --- /dev/null +++ b/app/testdata/libraries/LiyabBasic/examples/Liyab_Motors.ino @@ -0,0 +1,30 @@ +/* Liyab Basic Microcontroller - Motor Control */ + +#include + +void setup() { + Liyab_Init(); + OK(); +} + +void loop() { +motor(1, 50); +motor(2, 50); +delay(1000); + +motor(1, -50); +motor(2, -50); +delay(1000); + +motor(1, 50); +motor(2, -50); +delay(1000); + +motor(1, -50); +motor(2, 50); +delay(1000); + +motor(1, 0); +motor(2, 0); +delay(1000); +} diff --git a/app/testdata/libraries/LiyabBasic/library.properties b/app/testdata/libraries/LiyabBasic/library.properties new file mode 100644 index 0000000000..6e839d5f07 --- /dev/null +++ b/app/testdata/libraries/LiyabBasic/library.properties @@ -0,0 +1,9 @@ +name=LiyabBasic +version=1.0.0 +author=John David Golenia +maintainer=John David Golenia +sentence=Library for Liyab Basic Microcontroller +paragraph=This library facilitates the use of the Liyab Basic Microcontroller produced by GearTech Robots Trading, making robotics more user-friendly for beginners. +category=Uncategorized +url=https://github.com/TGC-GearTech/LiyabBasic +architectures=* diff --git a/app/testdata/libraries/LiyabBasic/src/LiyabBasic.cpp b/app/testdata/libraries/LiyabBasic/src/LiyabBasic.cpp new file mode 100644 index 0000000000..59704f81ad --- /dev/null +++ b/app/testdata/libraries/LiyabBasic/src/LiyabBasic.cpp @@ -0,0 +1,87 @@ +#include "Arduino.h" +#include "LiyabBasic.h" + +// Initialization function +void Liyab_Init() { + Serial.begin(9600); + + pinMode(2, OUTPUT); // Buzzer pin + + pinMode(9, OUTPUT); + pinMode(8, OUTPUT); + pinMode(7, OUTPUT); + pinMode(10, OUTPUT); + pinMode(11, OUTPUT); + pinMode(12, OUTPUT); + + // Play a sound on the buzzer + tone(2, 1250, 350); + tone(2, 1250, 350); +} + +// Function to wait until a button is pressed +void OK() { + pinMode(13, INPUT_PULLUP); + while (digitalRead(13) == 0) { + digitalWrite(13, LOW); + delay(100); + digitalWrite(13, HIGH); + } +} + +// Motor control function +void motor(uint8_t pin, int speed) { + if (pin == 1) { + if (speed > 0) { + int spd = map(speed, 0, 100, 0, 255); + analogWrite(9, spd); + digitalWrite(8, HIGH); + digitalWrite(7, LOW); + } + + if (speed < 0) { + int spd = map(speed, 0, -100, 0, 255); + analogWrite(9, spd); + digitalWrite(8, LOW); + digitalWrite(7, HIGH); + } + + if (speed == 0) { + analogWrite(9, 0); + digitalWrite(8, LOW); + digitalWrite(7, LOW); + } + } + + if (pin == 2) { // Motor 2 control + if (speed > 0) { + int spd = map(speed, 0, 100, 0, 255); + analogWrite(10, spd); + digitalWrite(11, HIGH); + digitalWrite(12, LOW); + } + + if (speed < 0) { + int spd = map(speed, 0, -100, 0, 255); + analogWrite(10, spd); + digitalWrite(11, LOW); + digitalWrite(12, HIGH); + } + + if (speed == 0) { + analogWrite(10, 0); + digitalWrite(11, LOW); + digitalWrite(12, LOW); + } + } +} + +// Stop both motors +void motor_stop() { + analogWrite(9, 0); + analogWrite(10, 0); + digitalWrite(8, LOW); + digitalWrite(7, LOW); + digitalWrite(11, LOW); + digitalWrite(12, LOW); +} diff --git a/app/testdata/libraries/LiyabBasic/src/LiyabBasic.h b/app/testdata/libraries/LiyabBasic/src/LiyabBasic.h new file mode 100644 index 0000000000..d6daf69d69 --- /dev/null +++ b/app/testdata/libraries/LiyabBasic/src/LiyabBasic.h @@ -0,0 +1,15 @@ +/* Liyab Basic Microcontroller Library */ +/* Written by GearTech Robots Trading */ + +#ifndef LiyabBasic_h +#define LiyabBasic_h + +#include "Arduino.h" + +// Function prototypes +void Liyab_Init(); +void OK(); +void motor(uint8_t pin, int speed); +void motor_stop(); + +#endif