-
Notifications
You must be signed in to change notification settings - Fork 275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to read pwm (led eg) in loop() ? #33
Comments
Paste your code here. |
the my_accessory.c `/*
*/ #include <Arduino.h> #define PIN_LED 2 int led_bri = 100; //[0, 100] homekit_value_t led_on_get() { void led_on_set(homekit_value_t value) { homekit_value_t light_bri_get() { void led_bri_set(homekit_value_t value) { void my_accessory_identify(homekit_value_t _value) { // Switch (HAP section 8.38) // format: bool; HAP section 9.70; write the .setter function to get the switch-event sent from iOS Home APP. // format: string; HAP section 9.62; max length 64 homekit_accessory_t accessories[] = { void led_update() { void occupancy_toggle() { // const uint8_t state = occupancy_detected.value.uint8_value; void led_toggle() { homekit_server_config_t config = { |
the main code "led.homekit.ino" `#include <Arduino.h> uint16_t OFF[171] = {6030, 1086, 1178, 436, 1178, 438, 460, 1148, 456, 1212, 458, 1148, 456, 1146, 1178, 440, 456, 1210, 456, 1150, 456, 1150, 458, 1148, 456, 1208, 1178, 436, 1202, 416, 458, 1146, 460, 1210, 458, 1148, 458, 1150, 456, 1150, 456, 1210, 456, 1144, 1176, 440, 460, 1150, 454, 1206, 1178, 438, 1204, 414, 456, 1150, 456, 1210, 456, 1148, 458, 1148, 458, 1146, 458, 1210, 456, 1152, 456, 1148, 456, 1148, 460, 1208, 456, 1144, 1206, 414, 458, 1148, 456, 1208, 1204, 414, 456, 1150, 456, 1150, 454, 1212, 456, 1150, 456, 1150, 456, 1146, 458, 1214, 452, 1150, 458, 1148, 456, 1150, 456, 1212, 458, 1144, 1174, 442, 458, 1148, 456, 1208, 1176, 442, 458, 1150, 454, 1152, 454, 1210, 458, 1148, 456, 1150, 456, 1148, 458, 1210, 456, 1150, 456, 1150, 456, 1150, 456, 1210, 458, 1144, 1174, 444, 456, 1152, 454, 1206, 1174, 444, 458, 1150, 454, 1152, 452, 1208, 1174, 444, 456, 1150, 458, 1144, 1200, 476, 1172, 442, 1202, 412, 1174, 440, 1200, 422, 1196}; // UNKNOWN AE963374 #define LOG_D(fmt, ...) printf_P(PSTR(fmt "\n") , ##VA_ARGS); // access your HomeKit characteristics defined in my_accessory.c #define PIN_SWITCH 2 //Relay pin void blink_led(int interval, int count) { void setup() { // pinMode (irLed, OUTPUT); void loop() { } void builtinledSetStatus(bool on) { //============================== ButtonDebounce btn(0, INPUT_PULLUP, LOW); void IRAM_ATTR btnInterrupt() { static uint32_t next_heap_millis = 0; //Called when the switch value is changed by iOS Home APP // int pwm = PWMRANGE - (int) (led_bri * 1.0 * PWMRANGE / 100.0 + 0.5f); void my_homekit_setup() { //Add the .setter function to get the switch-event sent from iOS Home APP. // led_bri.setter = led_on_setter; //report the switch value to HomeKit if it is changed (e.g. by a physical button) void my_homekit_loop() { } |
Read the Example01~04 to understand the full logic. Your characteristic
BTW, the .setter and .getter functions logic is as follows:
I do think the design (by author maximkulkin) of |
thank you so much for your help in my code. I even upgraded my skills to include many accessories :) |
Hello,
I am noob kind-of, I uploaded the LED sketch example and it works fine, but i need to do stuff in loop() for the value of pwm written or given through the Home app.
I wanted to run infrared signal "code" through an IRLed, when i set led pwm to 20, will send code 20 "IRSend library" to air-conditioner.
the issue is I cant get to read the pwm in loop (main tab called led) , neither can use the library or send the code in (my_accessory.h tab)
I tried Serial.println(led_bri.value.int_value); but always gives me same value 6510
I was able to get the ON/OFF state, but not the pwm value.
I know im missing something
i tried many things but all lead to fail.
thank you for your time.
The text was updated successfully, but these errors were encountered: