需要拿光敏电阻控制舵机的启动 求大佬帮助-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 4980|回复: 4

需要拿光敏电阻控制舵机的启动 求大佬帮助

[复制链接]
发表于 2018-5-17 21:22 | 显示全部楼层 |阅读模式
很急!今天就要做出来的程序。就是光敏电阻当光强到一定强度时 舵机要运作
现在舵机的程序单独做出来了 试运作也成功了
但是现在就是光敏和舵机不会结合起来。老师让找光控的程序代码 类推   我找到了光控LED小灯的程序代码 但是不会改 求大佬帮助
这是复制的光控led小灯代码 老师改了一点 说什么用串口监视器看光敏还是没懂

int dqvPin = 5; //读取环境光线强度
int LED = 13; //定义LED接口 D13
int val = 0; //定义光线强度变量值
void setup() {
pinMode(LED,OUTPUT); //设置D13为输出模式
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
}
void loop() {
val = analogRead(dqvPin); //读取环境光线强度值
Serial.println(val);
   delay(10)


*/
//if(val <= 70){
//digitalWrite(LED,HIGH); //如果读取到的环境亮度值小于等于70,那么LED亮,
//}
//else{
//digitalWrite(LED,LOW); //如果读取到的环境亮度值大于70,那么LED熄灭。
//}
}

 楼主| 发表于 2018-5-17 21:31 | 显示全部楼层
/* Sweep
by BARRAGAN <http://barraganstudio.com>
This example code is in the public domain.

modified 8 Nov 2013
by Scott Fitzgerald
http://arduino.cc/en/Tutorial/Sweep
*/

#include <Servo.h>

Servo myservo;  // create servo object to control a servo
                // twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position

void setup()
{
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}

void loop()
{
  for(pos = 0; pos <= 75; pos += 1) // goes from 0 degrees to 180 degrees
  {                                  // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for(pos = 75; pos>=0; pos-=1)     // goes from 180 degrees to 0 degrees
  {                                
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
}
 楼主| 发表于 2018-5-17 21:32 | 显示全部楼层
仙女本尊 发表于 2018-5-17 21:31
/* Sweep
by BARRAGAN  
This example code is in the public domain.

这是舵机的程序代码
发表于 2018-5-17 21:42 | 显示全部楼层
#include <Servo.h>
Servo myservo;
int dqvPin = 5; //读取环境光线强度
int LED = 13; //定义LED接口D13
int val = 0; //定义光线强度变量值
int pos = 0;


void setup()
{
        pinMode(LED,OUTPUT); //设置D13为输出模式
        Serial.begin(9600); //打开串口,设置数据速率为9600 bps
}
void loop()
{
        val = analogRead(dqvPin); //读取环境光线强度值
        Serial.println(VAL);
    delay(10)


        if(val <= 70)
        {
        digitalWrite(LED,HIGH);
        void pos(); //如果读取到的环境亮度值小于等于70,那么LED亮,
        }
        else
        {
         digitalWrite(LED,LOW); //如果读取到的环境亮度值大于70,那么LED熄灭。//
        }
}


void pos()
{
  for(pos = 0; pos <= 75; pos + = 1)//从0度到180度
  {//以1度
    myservo.write(pos)的步骤; //告诉伺服变量'pos'
    延迟(15); //等待伺服器到达位置
  } 15ms
  (pos = 75; pos> = 0; pos- = 1)//从180度到0度
  {                                 
    myservo.write(pos); //告诉伺服变量'pos'
    延迟(15); //等待伺服器达到15ms位置
  }
}
 楼主| 发表于 2018-5-17 21:55 | 显示全部楼层










long_.ino:9:1: error: stray '\' in program
long_.ino:9:1: error: stray '\' in program
long_.ino:11:9: error: stray '\' in program
long_.ino:11:9: error: stray '\' in program
long_.ino:11:9: error: stray '\' in program
long_.ino:12:9: error: stray '\' in program
long_.ino:12:9: error: stray '\' in program
long_.ino:14:1: error: stray '\' in program
long_.ino:14:1: error: stray '\' in program
long_.ino:16:9: error: stray '\' in program
long_.ino:16:9: error: stray '\' in program
long_.ino:17:9: error: stray '\' in program
long_.ino:17:9: error: stray '\' in program
long_.ino:18:5: error: stray '\' in program
long_.ino:18:5: error: stray '\' in program
long_.ino:21:9: error: stray '\' in program
long_.ino:21:9: error: stray '\' in program
long_.ino:23:9: error: stray '\' in program
long_.ino:23:9: error: stray '\' in program
long_.ino:23:9: error: stray '\' in program
long_.ino:24:9: error: stray '\' in program
long_.ino:24:9: error: stray '\' in program
long_.ino:28:10: error: stray '\' in program
long_.ino:28:10: error: stray '\' in program
long_.ino:28:10: error: stray '\' in program
long_.ino:33:1: error: stray '\' in program
long_.ino:33:1: error: stray '\' in program
long_.ino:35:3: error: stray '\' in program
long_.ino:35:3: error: stray '\' in program
long_.ino:37:5: error: stray '\' in program
long_.ino:37:5: error: stray '\' in program
long_.ino:37:5: error: stray '\' in program
long_.ino:37:5: error: stray '\' in program
long_.ino:37:5: error: stray '\' in program
long_.ino:38:5: error: stray '\' in program
long_.ino:38:5: error: stray '\' in program
long_.ino:38:5: error: stray '\' in program
long_.ino:38:5: error: stray '\' in program
long_.ino:39:5: error: invalid suffix "ms" on integer constant
long_.ino:40:3: error: stray '\' in program
long_.ino:40:3: error: stray '\' in program
long_.ino:42:5: error: stray '\' in program
long_.ino:42:5: error: stray '\' in program
long_.ino:43:5: error: stray '\' in program
long_.ino:43:5: error: stray '\' in program
long_.ino:43:5: error: stray '\' in program
long_.ino:43:5: error: stray '\' in program
long_.ino:9:12: error: expected initializer before 'uff08'
long_.ino:14:11: error: expected initializer before 'uff08'
编译有误。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|手机版|Arduino中文社区

GMT+8, 2024-12-28 17:49 , Processed in 0.073240 second(s), 15 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表