diff options
| author | Gustavoeklund01 <eklundgu@gmail.com> | 2025-10-27 19:15:23 -0300 |
|---|---|---|
| committer | Gustavoeklund01 <eklundgu@gmail.com> | 2025-10-27 19:15:23 -0300 |
| commit | 4008253dfd2005da102f6da06389268ecef152f6 (patch) | |
| tree | d8e7efa5262fcd212a0a30d647dcf12eb742fab2 /esp/AS5600.ino | |
| parent | f8b53f993ac61e470bcc1ee321c16a0657cf161d (diff) | |
conciliação dos sensores do esp32
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(); - } -} |
