Some code adjustments to PWM.

This commit is contained in:
Marvin Blum
2017-03-31 19:32:37 +02:00
parent 9f58ccfd83
commit 2af06f8e0a
2 changed files with 4 additions and 4 deletions

View File

@@ -136,13 +136,13 @@ unsigned int analog_read(unsigned char pin){
return ADC; return ADC;
} }
// TODO: write PWM to digital pins which allow it // TODO support more than pin 6!
void analog_write(unsigned char pin, unsigned char value){ void analog_write(unsigned char pin, unsigned char value){
if(pin != 3 && pin != 5 && pin != 6 && pin != 9 && pin != 10 && pin != 11){ if(pin != 3 && pin != 5 && pin != 6 && pin != 9 && pin != 10 && pin != 11){
return; return;
} }
// TODO maybe set pin mode? pin_mode(pin, OUTPUT);
// clear timer on compare match // clear timer on compare match
TCCR0A |= _BV(COM0A1)|_BV(WGM01)|_BV(WGM00); TCCR0A |= _BV(COM0A1)|_BV(WGM01)|_BV(WGM00);
@@ -171,5 +171,5 @@ ISR(ADC_vect){
// fast PWM overflow interrupt handler // fast PWM overflow interrupt handler
ISR(TIMER0_OVF_vect){ ISR(TIMER0_OVF_vect){
// required but not used...
} }

2
main.c
View File

@@ -33,7 +33,6 @@ void prepare(){
// PWM example // PWM example
pin_mode(A1, INPUT); pin_mode(A1, INPUT);
pin_mode(6, OUTPUT);
} }
unsigned char pwm = 0; unsigned char pwm = 0;
@@ -56,6 +55,7 @@ void loop(){
// PWM example // PWM example
int analog = map(analog_read(A1), 0, 1023, 0, 255); int analog = map(analog_read(A1), 0, 1023, 0, 255);
analog_write(3, analog);
analog_write(6, analog); analog_write(6, analog);
char out[15]; char out[15];