Skip to content

Commit 8c8adac

Browse files
v2.1.0
Edited Balancing bot, added example for WiFi - LED turn on/off Edited keywords.
1 parent 77beb28 commit 8c8adac

File tree

5 files changed

+124
-4
lines changed

5 files changed

+124
-4
lines changed

examples/RoboHeartBalanceBot/RoboHeartBalanceBot.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ RoboHeart heart = RoboHeart(Serial);
2222

2323
// PID controller parameters
2424
#define Kp 20
25-
#define Kd 0.001
25+
#define Kd 0
2626
#define Ki 40
2727

2828
#define CONTROL_TICK_PERIOD_US 100.0

examples/RoboHeartBalanceBotContol/RoboHeartBalanceBotContol.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ RoboHeart heart = RoboHeart(Serial);
2626

2727
// PID controller parameters
2828
#define Kp 20
29-
#define Kd 0.001
29+
#define Kd 0
3030
#define Ki 40
3131

3232
#define CONTROL_TICK_PERIOD_US 100.0 // Control tick period in micro-seconds
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/* This example shows how to create WiFi Access point
2+
* and control built-in LED.
3+
*
4+
* Created 30/01/2022
5+
* By Augmented Robotics
6+
*
7+
* Check out https://roboheart.de/en_gb/ for more information about RoboHeart.
8+
*/
9+
10+
11+
#include <RoboHeart.h>
12+
#include <WiFi.h>
13+
14+
#define ROBOHEART_AP_SSID "RoboHeart WiFi"
15+
#define ROBOHEART_AP_PASSWORD "Hercules4Makers"
16+
17+
WiFiServer server(80);
18+
// Current time
19+
unsigned long currentTime = millis();
20+
// Previous time
21+
unsigned long previousTime = 0;
22+
// Define timeout time in milliseconds (example: 2000ms = 2s)
23+
const long timeoutTime = 2000;
24+
25+
void setup()
26+
{
27+
Serial.begin(115200);
28+
Serial.println("\nCreating AP.");
29+
WiFi.mode(WIFI_AP);
30+
WiFi.softAP(ROBOHEART_AP_SSID, ROBOHEART_AP_PASSWORD);
31+
Serial.print("AP Created with IP Gateway ");
32+
Serial.println(WiFi.softAPIP());
33+
34+
// Configure the LED pin
35+
pinMode(LED_ROBOHEART, OUTPUT);
36+
server.begin();
37+
}
38+
39+
void loop(){
40+
WiFiClient client = server.available(); // Listen for incoming clients
41+
String header;
42+
if (client) {
43+
currentTime = millis();
44+
previousTime = currentTime;
45+
Serial.println("New Client."); // print a message out in the serial port
46+
String currentLine = ""; // make a String to hold incoming data from the client
47+
while (client.connected() && currentTime - previousTime <= timeoutTime) { // loop while the client's connected
48+
currentTime = millis();
49+
if (client.available()) { // if there's bytes to read from the client,
50+
char c = client.read(); // read a byte, then
51+
Serial.write(c); // print it out the serial monitor
52+
header += c;
53+
if (c == '\n') { // if the byte is a newline character
54+
// if the current line is blank, you got two newline characters in a row.
55+
// that's the end of the client HTTP request, so send a response:
56+
if (currentLine.length() == 0) {
57+
// HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
58+
// and a content-type so the client knows what's coming, then a blank line:
59+
client.println("HTTP/1.1 200 OK");
60+
client.println("Content-type:text/html");
61+
client.println("Connection: close");
62+
client.println();
63+
64+
// turns the GPIOs on and off
65+
if (header.indexOf("GET /LED_ROBOHEART/on") >= 0) {
66+
Serial.println("LED_ROBOHEART on");
67+
digitalWrite(LED_ROBOHEART, HIGH);
68+
} else if (header.indexOf("GET /LED_ROBOHEART/off") >= 0) {
69+
Serial.println("LED_ROBOHEART off");
70+
digitalWrite(LED_ROBOHEART, LOW);
71+
}
72+
73+
// Display the HTML web page
74+
client.println("<!DOCTYPE html><html>");
75+
client.println("<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">");
76+
client.println("<link rel=\"icon\" href=\"data:,\">");
77+
// CSS to style the on/off buttons
78+
// Feel free to change the background-color and font-size attributes to fit your preferences
79+
client.println("<style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}");
80+
client.println(".button { background-color: #4CAF50; border: none; color: white; padding: 16px 40px;");
81+
client.println("text-decoration: none; font-size: 30px; margin: 2px; cursor: pointer;}");
82+
client.println(".button2 {background-color: #555555;}</style></head>");
83+
84+
// Web Page Heading
85+
client.println("<body><h1>RoboHeart Access Point Example</h1>");
86+
87+
// Display current state, and ON/OFF buttons for LED_ROBOHEART
88+
client.println("<p>LED_ROBOHEART - State " + String((digitalRead(LED_ROBOHEART) == HIGH) ? "on" : "off") + "</p>");
89+
90+
if ((digitalRead(LED_ROBOHEART))==LOW) {
91+
client.println("<p><a href=\"/LED_ROBOHEART/on\"><button class=\"button\">LED ON</button></a></p>");
92+
} else {
93+
client.println("<p><a href=\"/LED_ROBOHEART/off\"><button class=\"button button2\">LED OFF</button></a></p>");
94+
}
95+
96+
client.println("</body></html>");
97+
98+
// The HTTP response ends with another blank line
99+
client.println();
100+
// Break out of the while loop
101+
break;
102+
} else { // if you got a newline, then clear currentLine
103+
currentLine = "";
104+
}
105+
} else if (c != '\r') { // if you got anything else but a carriage return character,
106+
currentLine += c; // add it to the end of the currentLine
107+
}
108+
}
109+
}
110+
// Clear the header variable
111+
header = "";
112+
// Close the connection
113+
client.stop();
114+
Serial.println("Client disconnected.");
115+
Serial.println("");
116+
}
117+
}

keywords.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ start KEYWORD2
4141
stop KEYWORD2
4242
setTimePeriod KEYWORD2
4343
resetGyro KEYWORD2
44+
4445
###################################################################
4546
# Constants
4647
###################################################################
@@ -77,4 +78,6 @@ RH_APP_SERVICE_UUID LITERAL1
7778
RH_APP_CHARACTERISTIC_UUID1 LITERAL1
7879
RH_APP_CHARACTERISTIC_UUID2 LITERAL1
7980
RH_APP_CHARACTERISTIC_UUID3 LITERAL1
80-
STEPPER_MOTOR_MAX_STEPS LITERAL1
81+
STEPPER_MOTOR_MAX_STEPS LITERAL1
82+
ROBOHEART_AP_SSID LITERAL1
83+
ROBOHEART_AP_PASSWORD LITERAL1

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=RoboHeart
2-
version=2.0.5
2+
version=2.1.0
33
author=Augmented Robotics
44
maintainer=Augmented Robotics <[email protected]>
55
sentence=Arduino library for the RoboHeart

0 commit comments

Comments
 (0)