mirror of
https://github.com/Kugelschieber/arduino-c.git
synced 2026-09-13 12:21:48 +00:00
Some code adjustments to PWM.
This commit is contained in:
+3
-3
@@ -136,13 +136,13 @@ unsigned int analog_read(unsigned char pin){
|
||||
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){
|
||||
if(pin != 3 && pin != 5 && pin != 6 && pin != 9 && pin != 10 && pin != 11){
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO maybe set pin mode?
|
||||
pin_mode(pin, OUTPUT);
|
||||
|
||||
// clear timer on compare match
|
||||
TCCR0A |= _BV(COM0A1)|_BV(WGM01)|_BV(WGM00);
|
||||
@@ -171,5 +171,5 @@ ISR(ADC_vect){
|
||||
|
||||
// fast PWM overflow interrupt handler
|
||||
ISR(TIMER0_OVF_vect){
|
||||
|
||||
// required but not used...
|
||||
}
|
||||
|
||||
@@ -33,7 +33,6 @@ void prepare(){
|
||||
|
||||
// PWM example
|
||||
pin_mode(A1, INPUT);
|
||||
pin_mode(6, OUTPUT);
|
||||
}
|
||||
|
||||
unsigned char pwm = 0;
|
||||
@@ -56,6 +55,7 @@ void loop(){
|
||||
|
||||
// PWM example
|
||||
int analog = map(analog_read(A1), 0, 1023, 0, 255);
|
||||
analog_write(3, analog);
|
||||
analog_write(6, analog);
|
||||
|
||||
char out[15];
|
||||
|
||||
Reference in New Issue
Block a user