diff options
| author | Luiz Gustavo Monteiro <luizgu_mreis@hotmail.com> | 2025-10-28 20:25:17 -0300 |
|---|---|---|
| committer | Luiz Gustavo Monteiro <luizgu_mreis@hotmail.com> | 2025-10-28 20:25:17 -0300 |
| commit | 6fed254c8033bf4c67b65328474df6807c3b7eb8 (patch) | |
| tree | ce57462722cdae066b706a78a06d586b5170951b /esp/AS5600.ino | |
| parent | 52a4fe2625b63683fcdcd74f704e49aa65cb0dd8 (diff) | |
refactor folders schema
Diffstat (limited to 'esp/AS5600.ino')
| -rw-r--r-- | esp/AS5600.ino | 47 |
1 files changed, 0 insertions, 47 deletions
diff --git a/esp/AS5600.ino b/esp/AS5600.ino deleted file mode 100644 index 233aa13..0000000 --- a/esp/AS5600.ino +++ /dev/null @@ -1,47 +0,0 @@ -#include <Wire.h> - -#define AS5600_ADDR 0x36 // endereço I2C do AS5600 -#define RAW_ANGLE_REG 0x0C - -unsigned long lastTime = 0; - -String direcaoCardinal(float angulo) { - if (angulo >= 337.5 || angulo < 22.5) return "Norte"; - else if (angulo < 67.5) return "Nordeste"; - else if (angulo < 112.5) return "Leste"; - else if (angulo < 157.5) return "Sudeste"; - else if (angulo < 202.5) return "Sul"; - else if (angulo < 247.5) return "Sudoeste"; - else if (angulo < 292.5) return "Oeste"; - else return "Noroeste"; -} - -uint16_t readRawAngle() { - Wire.beginTransmission(AS5600_ADDR); - Wire.write(RAW_ANGLE_REG); - Wire.endTransmission(); - Wire.requestFrom(AS5600_ADDR, 2); - uint16_t high = Wire.read(); - uint16_t low = Wire.read(); - return (high << 8) | low; -} - -void setup() { - Serial.begin(115200); - Wire.begin(); // SDA e SCL padrão do ESP32 (21 e 22) - Serial.println("Leitura do AS5600 - Direcao do Vento"); -} - -void loop() { - uint16_t raw = readRawAngle(); - // O AS5600 fornece 12 bits (0–4095) para 0–360° - float angulo = (raw & 0x0FFF) * 360.0 / 4096.0; - - if (millis() - lastTime >= 1000) { - Serial.print("Angulo: "); - Serial.print(angulo, 2); - Serial.print("° | Direcao: "); - Serial.println(direcaoCardinal(angulo)); - lastTime = millis(); - } -} |
