This one also didn't work:
#include "util/delay.h"
#include "avr/io.h"
#define OCR1_MIN 2000
#define OCR1_GAIN 2000
void setup() {
// put your setup code here, to run once:
// Setup Timer1
//TCCR1A|=(1<<COM1A1)|(1<<COM1B1)|(1<<WGM11); //NON Inverted PWM
//TCCR1B|=(1<<WGM13)|(1<<WGM12)|(1<<CS11)|(1<<CS10); //PRESCALER=64 MODE=14(FAST PWM)
//TCCR1B|=(1<<WGM13)|(1<<WGM12)|(1<<CS11); //PRESCALER=8 MODE=14(FAST PWM)
//ICR1=4999; //fPWM=50Hz
TCCR1A = 0b10100010;
TCCR1B = 0b00011010; //PRESCALER=8 MODE=14(FAST PWM)
//ICR1=4999; //fPWM=50Hz
ICR1 = 40000;
ADCSRA = 0b11000111;
// Setup ADC
ADCSRA = (1<<ADSC) | (1<<ADEN) | (1<<ADPS2)| (1<<ADPS1) | (1<<ADPS0);//ADEN: ADC Enable
//Writing this bit to one enables the ADC.
//ADC Prescaler Selections
//111 for 128
// Setup signal pins for 2 servos
//DDRB |= (1 << PB2)|(1 << PB1); //PWM Pins as Output
DDRB = 0b00000110;
}
void loop() {
write_arm_motors(read_knob_sensor(0),read_knob_sensor(1));
}
void write_arm_motors(float motor0, float motor1){
OCR1A = OCR1_GAIN*motor0+OCR1_MIN;
OCR1B = OCR1_GAIN*motor1+OCR1_MIN;
return;
}
float read_knob_sensor(int knob){
float reading = 0; /* Sensor reading, normalised
(i.e., scaled) to be between
zero and one. */
//ADCSRA = (1<<ADSC) | (1<<ADEN) | (1<<ADPS2)| (1<<ADPS1) | (1<<ADPS0);
if(knob == 1){
ADMUX |= 0b01100000; // ADC on Channel 0
} else if(knob == 0){
ADMUX |= 0b01100001; // ADC on Channel 1
}
//_delay_ms(15);
int readingInter = 0;
readingInter = ADCW>>6;
reading = readingInter / 1023.0;
_delay_ms(15);
//printf("reading = %f\n", reading);
return reading;
}