SCoop Arduino

时间:2024-06-02 16:42:26
【文件属性】:

文件名称:SCoop Arduino

文件大小:655KB

文件格式:ZIP

更新时间:2024-06-02 16:42:26

SCoop Arduino

Arduino中SCoop多线程库 实例程序代码 /*#include #include */ #include //多线程程序库 #include //超声波传感器 #include //电机传感器 //LiquidCrystal_I2C lcd(0x27,16,2); defineTask(LEDTask);//LED 灯的线程 defineTask(ServoTask);//舵机线程 #define TRIGGER_PIN 2 #define ECHO_PIN 3 #define MAX_DISTANCE 400 NewPing sonar(TRIGGER_PIN,ECHO_PIN,MAX_DISTANCE);//超声波传感器 Servo myservo;//电机传感器 const int replyPin=A2;//光敏传感器 const int soundPin=A0;//声音传感器 const int senorPin=8;//触摸感应键 const int rPin=7;//Led const int ledPin=6; //Led int value=0;//光敏传感器 int sound=0;//声音传感器 int Senor=-1; void LEDTask::setup(){ pinMode(replyPin,INPUT); pinMode(soundPin,INPUT); pinMode(rPin,OUTPUT); } void LEDTask::loop(){ value=analogRead(replyPin);//光敏传感器感应到光强度 Serial.print("光敏传感器感应到光强度:"); Serial.println(value); sound=analogRead(soundPin);//声音感应器感应到声音大小 Serial.print("声音感应器感应到声音大小:"); Serial.println(sound); unsigned int uS=sonar.ping();//超声波传感器感应到数据 Serial.print("超声波传感器感应到数据:"); Serial.println(uS/US_ROUNDTRIP_CM); if(value>400&&(sound>80||uS/US_ROUNDTRIP_CM<5)){ analogWrite(rPin,255); analogWrite(ledPin,0); delay(5000); }else{ analogWrite(rPin,0); analogWrite(ledPin,0); } } void ServoTask::setup(){ pinMode(senorPin,INPUT); myservo.attach(9); myservo.write(0); } void ServoTask::loop(){ Senor=digitalRead(senorPin);//触摸感应键感应 Serial.print("触摸感应键感应:"); Serial.println(Senor); if(Senor==1){ myservo.write(30); delay(100); myservo.write(60); delay(100); myservo.write(90); delay(3000); myservo.write(60); delay(100); myservo.write(30); delay(100); myservo.write(0); } } void setup(){ mySCoop.start(); Serial.begin(9600); } void loop(){ yield(); } //这段程序有一个舵机、一个LED灯(两者都是执行器),两个执行器执行时需要相互不干扰,所以使用多线程


【文件预览】:
SCoop-fix_scoop_compil
----README.txt(228B)
----TimerUp()
--------TimerUp.cpp(3KB)
--------keywords.txt(841B)
--------examples()
--------TimerUp.h(4KB)
--------readme.txt(161B)
----SCoop()
--------SCoop.h(34KB)
--------keywords.txt(718B)
--------SCoop.cpp(38KB)
--------examples()
--------scoop change log.txt(8KB)
----SCoop user guide V1.2.pdf(652KB)
----IOFilter()
--------IOFilter.h(4KB)
--------IOFilter.cpp(4KB)
--------examples()
----.gitignore(2KB)
----SchedulerARMAVR()
--------SchedulerARMAVR.cpp(7KB)
--------keywords.txt(481B)
--------SchedulerARMAVR.h(3KB)
--------examples()
----.gitattributes(483B)
----TimerDown()
--------keywords.txt(816B)
--------TimerDown.cpp(2KB)
--------examples()
--------TimerDown.h(3KB)
--------readme.txt(161B)

网友评论