Arduino: Debugging with an ATtiny? (2 Solutions!!)

preview_player
Показать описание
Arduino: Debugging with an ATtiny?

Рекомендации по теме
Комментарии
Автор

please help me i my projects isnt working.heres the info below.
the issue is when i connect PB3 to 5v its not blinking 5 times. its not blinking at all

//this is a simple program to test the functionality of the ADC for attiny85

#include <avr/io.h>
#define PIN_VOLTMETER PB3
#define PIN_LED PB4


void setup() {

volatile byte* ADMUX_K= reinterpret_cast<volatile byte*>(0x07);
volatile byte* ADCSRA_K= reinterpret_cast<volatile byte*>(0x06);
volatile byte* ADCH_K= reinterpret_cast<volatile byte*>(0x05);
volatile byte* ADCL_K= reinterpret_cast<volatile byte*>(0x04);

double voltage;

DDRB |= (1<<PIN_LED); //PB4 as OUTPUT
DDRB &= ~(1<<PIN_VOLTMETER); //PBR3 as INPUT

//connect PB3 to adc
*ADMUX_K |= 3; //ADMUX REGISTER(0000 0011) //select PB3 as adc //enable adc //start conversion

//enable adc //start conversion
delay(20);
*ADCSRA_K |= 192;
delay(20);

while(*ADCSRA_K & (1<<6));

//getadc results
delay(100);
byte ADCH_K_VALUE = *ADCH_K;
byte ADCL_K_VALUE = *ADCL_K;

voltage = (ADCH_K_VALUE<<8) | ADCL_K_VALUE;
delay(3);

//blink the led as many times as the measured voltage at PB3.Example for 4.5V it will blink 4 times
for(int i=0 ; i<voltage ; i+100){
PORTB |= (1<<PIN_LED);
delay(1000);
PORTB &= ~(1<<PIN_LED);
delay(1000);

}

delay(5000);

}

kenjiyoshida
welcome to shbcf.ru