Skip to content

Instantly share code, notes, and snippets.

@AnandChowdhary
Created October 17, 2018 20:20
Show Gist options
  • Save AnandChowdhary/b15a5f10c610bc888f944db63324bd9a to your computer and use it in GitHub Desktop.
Save AnandChowdhary/b15a5f10c610bc888f944db63324bd9a to your computer and use it in GitHub Desktop.
#define analogInPin 0
const float Pi = 3.141592;
char sensorValue[480];
char outputValue[480];
int number,frameCurrent;
int pos0value, pos90value;
void setup() {
Serial.begin(38400);
for(int n=0;n<480;n++){
outputValue[n]=(char)127*sin((float)2*Pi*n/48)+127;
}
TCCR1B=1;
TCCR0B=1;
TCCR2A = 0;
TCCR2B = 4;
TIMSK2 = 1<<TOIE2;
TCNT2 = 0xce;
}
void loop() {
if (frameCurrent>0){
float sinX = (float)(pos90value - 712) / 105;
float cosX = (float)(pos0value - 712) / 105;
Serial.print(atan2(sinX,cosX)/Pi * 180);
Serial.print('\t');
Serial.println((float)analogRead(A1)/1023 * 10 * 360 - 320);
frameCurrent = 0;
}
}
ISR(TIMER2_OVF_vect) {
if(number == 0) pos0value = analogRead(analogInPin);
if(number == 11) pos90value = analogRead(analogInPin);
TCNT2 = 0xce;
analogWrite(9, outputValue[number]);
analogWrite(5, outputValue[(number+16)%480]);
analogWrite(6, outputValue[(number+32)%480]);
sensorValue[number]=analogRead(analogInPin)/8;
value)
number++;
if(number>479) {number=0;frameCurrent++; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment