Hi everyone, I hope a lot in your help, I have a circuit with attiny85 that does on off with sleep, etc., I would like you to control a led driver in pwm but I don't know how to do it.
https://www.flashled.com.ua/imag...
#include <avr/sleep.h> #include <avr/power.h> const byte LED = 1; // D1 / pin 2 const byte SWITCH = 2; // D2 / pin 6 / PCINT2 volatile byte last_sw_state = HIGH; volatile byte led_state = LOW; volatile long last_sw_change_millis = 0; byte sw_state = HIGH; long sw_read_millis = 0; // Interrupt Service Request. Executed when the state of the pin changes ISR(PCINT0_vect) { } void setup() { pinMode (LED, OUTPUT); pinMode (SWITCH, INPUT_PULLUP); cli(); // Disable interrupt // Pin change interrupt PCMSK |= bit (PCINT2); // D2 / pin 7 GIFR |= bit (PCIF); // Clear any outstanding interrupts GIMSK |= bit (PCIE); // Enable pin change interrupts sei(); // Enable interrupt } void loop() { sw_state = digitalRead(SWITCH); // or faster: (PINB >> PINB2) & 1 sw_read_millis = millis(); if (last_sw_state==HIGH && sw_state==LOW) { // Falling edge last_sw_change_millis = sw_read_millis; } if (last_sw_state==LOW && sw_state==LOW && sw_read_millis-last_sw_change_millis>1000) { led_state = !led_state; digitalWrite (LED, led_state); enter_sleep (); } last_sw_state = sw_state; } void enter_sleep () { // Enter sleep set_sleep_mode(SLEEP_MODE_PWR_DOWN); ADCSRA = 0; // Turn off ADC power_all_disable (); // Power off ADC, Timer 0 and 1, serial interface sleep_enable(); sleep_cpu(); // …zzz // Wake up sleep_disable(); power_all_enable(); // Power everything back on }