我上面的代码就可以改成你说的这样,定时器计时到某一时刻,开中断Interrupts(),过一段时间,再关闭中断n ...
我想用arduino控制三个工业级的步进电机,发送三个不同频率的脉冲,使得三路步进电机的转速都不同,请问怎么结合这个库和定时库来实现这个功能 servotimer.setTimer(25);是给线程跳出的时间么? PT_timer 在 Add .ZIP Library 的时候出问题了!
ProtoThreads 没问题!
错误代码:
//Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: MALFORMED
at java.util.zip.ZipCoder.toString(ZipCoder.java:58)
at java.util.zip.ZipFile.getZipEntry(ZipFile.java:567)
at java.util.zip.ZipFile.access$900(ZipFile.java:61)
at java.util.zip.ZipFile$ZipEntryIterator.next(ZipFile.java:525)
at java.util.zip.ZipFile$ZipEntryIterator.nextElement(ZipFile.java:500)
at java.util.zip.ZipFile$ZipEntryIterator.nextElement(ZipFile.java:481)
at processing.app.tools.ZipDeflater.deflate(ZipDeflater.java:41)
at processing.app.Base.handleAddLibrary(Base.java:2479)
at processing.app.Base$11.actionPerformed(Base.java:1179)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2346)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.AbstractButton.doClick(AbstractButton.java:376)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:833)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:877)
at java.awt.Component.processMouseEvent(Component.java:6525)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
at java.awt.Component.processEvent(Component.java:6290)
at java.awt.Container.processEvent(Container.java:2234)
at java.awt.Component.dispatchEventImpl(Component.java:4881)
at java.awt.Container.dispatchEventImpl(Container.java:2292)
at java.awt.Component.dispatchEvent(Component.java:4703)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4898)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4533)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4462)
at java.awt.Container.dispatchEventImpl(Container.java:2278)
at java.awt.Window.dispatchEventImpl(Window.java:2750)
at java.awt.Component.dispatchEvent(Component.java:4703)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.awt.EventQueue$4.run(EventQueue.java:729)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)// 你好,参照您的程序想学习一下多线程,但是电机却不转了,请问哪里出错了呢?先谢大神啦
#include <pt.h>
#include <PT_timer.h>
int intput1=5;
int intput2=6;
int pa = analogRead(A0);
int a = analogRead(A1);
int pb = analogRead(A2);
int b = analogRead(A3);
int aa;
static struct pt pt1,pt2;
PT_timer servotimer;
void setup()
{
//线程1初始化
Serial.begin(9600);
pinMode(intput1,OUTPUT);
pinMode(intput2,OUTPUT);
PT_INIT(&pt1);
}
void loop () //这就是进行线程调度的地方
{
protothread1(&pt1);//执行线程1
//delay(1000);//时间片,每片1秒,可根据具体应用设置大小
}
static int protothread1(struct pt *pt) //线程1,控制灯1
{
PT_BEGIN(pt);//线程开始
while(1) //每个线程都不会死
{
aa=a-pa;
if(aa>0)
{
digitalWrite(intput1,HIGH);//将舵机接口电平至高
digitalWrite(intput2,LOW);
}
else
{ if(aa<0)
{
digitalWrite(intput1,LOW);//将舵机接口电平至高
digitalWrite(intput2,HIGH);
}
else
{
digitalWrite(intput1,LOW);//将舵机接口电平至高
delayMicroseconds(100);//延时脉宽值的微秒数
digitalWrite(intput2,LOW);
delayMicroseconds(100);
}
}
PT_END(pt);
//线程结束
}
}
页:
1
[2]