Compare commits

..

No commits in common. "33cfcd5c91f2a9c7a5fe71d6e20d4eddfdc0e6fe" and "60a6db983222055d4211b44fca6f99621cc765ed" have entirely different histories.

View file

@ -1,4 +1,3 @@
// esp32 specific
#include <unordered_map> #include <unordered_map>
#include "WiFi.h" #include "WiFi.h"
@ -29,9 +28,9 @@ ServoPin servos[6] = {
// 00 // 00
// braille alphabet array // braille alphabet array
struct BrailleChar { struct BrailleChar {
int servo_states[6]; int servoStates[6];
}; };
std::unordered_map<char, BrailleChar> braille_map = { std::unordered_map<char, BrailleChar> brailleMap = {
{' ', {{ {' ', {{
0, 0, 0, 0,
0, 0, 0, 0,
@ -189,7 +188,8 @@ std::unordered_map<char, BrailleChar> braille_map = {
}}} }}}
}; };
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()); Serial.print(packet.length()); //dlzka packetu
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,25 +228,34 @@ 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); servos[i].servo.attach(servos[i].pin, 500, 2500); // full 180
} }
} }
char old_char = ' '; void loop()
void loop() { {
// delay(1000); // delay(1000);
// udp.broadcast("Anyone here?"); // udp.broadcast("Anyone here?");
if (in_char != old_char) { // for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
BrailleChar bc = braille_map[in_char]; // // in steps of 1 degree
for (int i = 0; i < 6; i++) { // myservo.write(pos); // tell servo to go to position in variable 'pos'
int state = bc.servo_states[i]; // delay(15); // waits 15ms for the servo to reach the position
int s = i % 2 == 0 ? state : (1 - state); // }
servos[i].servo.write(s * 180); // for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
} // myservo.write(pos); // tell servo to go to position in variable 'pos'
// delay(15); // waits 15ms for the servo to reach the position
// }
old_char = in_char; // myservo.write(bindex);
for (int i = 0; i < 6; i++) {
servos[i].servo.write(brailleMap[in_char].servoStates[i] * 180);
} }
} }