Untitled

mail@pastecode.io avatar
unknown
plain_text
6 months ago
835 B
6
Indexable
Never
#include <Servo.h>

Servo servo1;


void setup() {
 servo1.attach(7);

 Serial.begin(9600);


}



void loop() {

// A)
float t; //time
float theta; //angle
float A = 90.0;  //anmpltiude (degrees)  // Q:why is it needed here ?
float w = 5; //frequency (rad/s)
float pi = 3.1456;

int analog_input;
float analog_voltage;

t = micros()*1.0e-6;  //time in seconds

if((t > 0.0) &&  (t < 10*pi)){
theta = A*(1.0 + sin(w*t)); //Q : can you explain the equation ?
servo1.write(theta); 
analog_input = analogRead(A0); 
analog_voltage = analog_input/1023.0*5;
Serial.print("\nvoltage ="); // to print the voltage
Serial.print(analog_voltage*10);
} else { //to stop the program
  exit(0);
}



//B) 
Serial.print(t);
Serial.print(",");
Serial.print(analog_voltage);
Serial.print("\n");




}
Leave a Comment