赞
踩
#include <Servo.h>
#include <PID_v1.h>
Servo myservo; // create servo object to control a servo
int potpin = 0; // analog pin used to connect the potentiometer
float val; // variable to read the value from the analog pin
float vall;
float valls;
int scode=0;//speed test
float speeds;
unsigned long oldtime = 0, newtime;
double Setpoint,Input,Output;
double kp=2;
double ki=5;
double kd=0;
PID myPID(&Input,&Output,&Setpoint,kp,ki,kd,DIRECT);
int switchs;
void setup()
{Serial.begin(9600); // 初始化串口通信
attachInterrupt(0, code, CHANGE); // 设置码盘外部中断
myservo.attach(9);
Setpoint=80;
myPID.SetMode(AUTOMATIC);}
void loop()
{ newtime = millis();
if(newtime-oldtime>1000)
{
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。