Compare commits

...

3 commits

Author SHA1 Message Date
33cfcd5c91 chiral 2024-04-02 14:54:31 -04:00
0860b568af refresh on new char 2024-04-02 14:53:36 -04:00
41661cd05d better understanding of pwm 2024-04-02 14:13:03 -04:00

View file

@ -1,3 +1,4 @@
// esp32 specific
#include <unordered_map>
#include "WiFi.h"
@ -28,9 +29,9 @@ ServoPin servos[6] = {
// 00
// braille alphabet array
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,
@ -188,8 +189,7 @@ std::unordered_map<char, BrailleChar> brailleMap = {
}}}
};
void setup()
{
void setup() {
Serial.begin(115200);
WiFi.disconnect(true);
@ -206,7 +206,7 @@ void setup()
Serial.println(WiFi.localIP());
udp.onPacket([](AsyncUDPPacket packet) {
Serial.print(", Length: ");
Serial.print(packet.length()); //dlzka packetu
Serial.print(packet.length());
Serial.print(", Data: ");
// Serial.write(packet.data(), packet.length());
// that is printing a character instead of a number
@ -228,34 +228,25 @@ void setup()
ESP32PWM::allocateTimer(1);
ESP32PWM::allocateTimer(2);
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++) {
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);
// udp.broadcast("Anyone here?");
// for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// // in steps of 1 degree
// myservo.write(pos); // tell servo to go to position in variable 'pos'
// delay(15); // waits 15ms for the servo to reach the position
// }
// 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
// }
if (in_char != old_char) {
BrailleChar bc = braille_map[in_char];
for (int i = 0; i < 6; i++) {
int state = bc.servo_states[i];
int s = i % 2 == 0 ? state : (1 - state);
servos[i].servo.write(s * 180);
}
// myservo.write(bindex);
for (int i = 0; i < 6; i++) {
servos[i].servo.write(brailleMap[in_char].servoStates[i] * 180);
old_char = in_char;
}
}