Compare commits
3 commits
60a6db9832
...
33cfcd5c91
Author | SHA1 | Date | |
---|---|---|---|
33cfcd5c91 | |||
0860b568af | |||
41661cd05d |
1 changed files with 16 additions and 25 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
// esp32 specific
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
#include "WiFi.h"
|
#include "WiFi.h"
|
||||||
|
@ -28,9 +29,9 @@ ServoPin servos[6] = {
|
||||||
// 00
|
// 00
|
||||||
// braille alphabet array
|
// braille alphabet array
|
||||||
struct BrailleChar {
|
struct BrailleChar {
|
||||||
int servoStates[6];
|
int servo_states[6];
|
||||||
};
|
};
|
||||||
std::unordered_map<char, BrailleChar> brailleMap = {
|
std::unordered_map<char, BrailleChar> braille_map = {
|
||||||
{' ', {{
|
{' ', {{
|
||||||
0, 0,
|
0, 0,
|
||||||
0, 0,
|
0, 0,
|
||||||
|
@ -188,8 +189,7 @@ std::unordered_map<char, BrailleChar> brailleMap = {
|
||||||
}}}
|
}}}
|
||||||
};
|
};
|
||||||
|
|
||||||
void setup()
|
void setup() {
|
||||||
{
|
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
|
|
||||||
WiFi.disconnect(true);
|
WiFi.disconnect(true);
|
||||||
|
@ -206,7 +206,7 @@ void setup()
|
||||||
Serial.println(WiFi.localIP());
|
Serial.println(WiFi.localIP());
|
||||||
udp.onPacket([](AsyncUDPPacket packet) {
|
udp.onPacket([](AsyncUDPPacket packet) {
|
||||||
Serial.print(", Length: ");
|
Serial.print(", Length: ");
|
||||||
Serial.print(packet.length()); //dlzka packetu
|
Serial.print(packet.length());
|
||||||
Serial.print(", Data: ");
|
Serial.print(", Data: ");
|
||||||
// Serial.write(packet.data(), packet.length());
|
// Serial.write(packet.data(), packet.length());
|
||||||
// that is printing a character instead of a number
|
// that is printing a character instead of a number
|
||||||
|
@ -228,34 +228,25 @@ void setup()
|
||||||
ESP32PWM::allocateTimer(1);
|
ESP32PWM::allocateTimer(1);
|
||||||
ESP32PWM::allocateTimer(2);
|
ESP32PWM::allocateTimer(2);
|
||||||
ESP32PWM::allocateTimer(3);
|
ESP32PWM::allocateTimer(3);
|
||||||
// myservo.setPeriodHertz(50); // standard 50 hz servo
|
|
||||||
// myservo.attach(servoPin, 1000, 2000); // attaches the servo on pin x to the servo object
|
|
||||||
// using default min/max of 1000us and 2000us
|
|
||||||
// different servos may require different min/max settings
|
|
||||||
// for an accurate 0 to 180 sweep
|
|
||||||
for (int i = 0; i < 6; i++) {
|
for (int i = 0; i < 6; i++) {
|
||||||
servos[i].servo.setPeriodHertz(50);
|
servos[i].servo.setPeriodHertz(50);
|
||||||
servos[i].servo.attach(servos[i].pin, 500, 2500); // full 180
|
servos[i].servo.attach(servos[i].pin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
char old_char = ' ';
|
||||||
{
|
void loop() {
|
||||||
// delay(1000);
|
// delay(1000);
|
||||||
// udp.broadcast("Anyone here?");
|
// udp.broadcast("Anyone here?");
|
||||||
|
|
||||||
// for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
|
if (in_char != old_char) {
|
||||||
// // in steps of 1 degree
|
BrailleChar bc = braille_map[in_char];
|
||||||
// myservo.write(pos); // tell servo to go to position in variable 'pos'
|
for (int i = 0; i < 6; i++) {
|
||||||
// delay(15); // waits 15ms for the servo to reach the position
|
int state = bc.servo_states[i];
|
||||||
// }
|
int s = i % 2 == 0 ? state : (1 - state);
|
||||||
// for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
|
servos[i].servo.write(s * 180);
|
||||||
// myservo.write(pos); // tell servo to go to position in variable 'pos'
|
}
|
||||||
// delay(15); // waits 15ms for the servo to reach the position
|
|
||||||
// }
|
|
||||||
|
|
||||||
// myservo.write(bindex);
|
old_char = in_char;
|
||||||
for (int i = 0; i < 6; i++) {
|
|
||||||
servos[i].servo.write(brailleMap[in_char].servoStates[i] * 180);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue