kanshizhuo 发表于 2014-7-23 18:35:41

PT库不可以用delay,可以用delayMicroseconds吗?好像这也不行。

kanshizhuo 发表于 2014-7-23 18:38:07

我如果同时用pt,又用pwm,又用定时器1或2,这一定会有影响吧。大神,求使用具体条件。

老胖熊 发表于 2014-7-25 15:23:04

记号,留待以后学习。

zwltanf 发表于 2014-7-30 23:19:29

是不是每个时间片断的长度要比一个线程的执行时间不短?

qq367176275 发表于 2014-9-1 16:19:24


MARK一下:)

dreamable 发表于 2014-11-7 09:50:26

switch magic~~~ nice~~

for 发表于 2014-11-29 13:17:59

这个不错可以用来做ArduinoPLC的操作系统了:lol!!

简单侣图 发表于 2015-1-19 21:10:18

下载完您提供的库怎样我连第一个程序都通不过的啊,求解?
D:\arduino1.0.6\arduino\libraries\pt-1.4\example-codelock.c: In function 'clock_time':
D:\arduino1.0.6\arduino\libraries\pt-1.4\example-codelock.c:401: error: storage size of 'tv' isn't known
D:\arduino1.0.6\arduino\libraries\pt-1.4\example-codelock.c:402: error: storage size of 'tz' isn't known
:Q

wdb_9955 发表于 2015-2-27 11:56:43

我正在做一个sim900的 远程控制程序,现在的问题是 如果不加LCD显示,都正常,如果加了LCD 显示,sim900就不能完整的读取收到的信息内容,搞了好久都不能解决,今天看到这个贴子,试着用这个库,把sim900收到信息处理信息做一个线程,lcd显示做一个线程,这个库第一次使用,完全不会,我把代码传上来,大伙帮我看看,求指导!不胜感激!#include <pt.h>
#include <SoftwareSerial.h>
#include <String.h>
SoftwareSerial mySerial(7, 8);
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4);
#include <dht11.h>
#define DHT11PIN 9
#include <Wire.h>
dht11 DHT11;
int lastSMSnumber = 0;
String Str="";

int flag = 0;
double Fahrenheit(double celsius)
{
      return 1.8 * celsius + 32;
}    //摄氏温度度转化为华氏温度

double Kelvin(double celsius)
{
      return celsius + 273.15;
}   //摄氏温度转化为开氏温度

double dewPoint(double celsius, double humidity)
{
      double A0= 373.15/(273.15 + celsius);
      double SUM = -7.90298 * (A0-1);
      SUM += 5.02808 * log10(A0);
      SUM += -1.3816e-7 * (pow(10, (11.344*(1-1/A0)))-1) ;
      SUM += 8.1328e-3 * (pow(10,(-3.49149*(A0-1)))-1) ;
      SUM += log10(1013.246);
      double VP = pow(10, SUM-3) * humidity;
      double T = log(VP/0.61078);   // temp var
      return (241.88 * T) / (17.558-T);
}

double dewPointFast(double celsius, double humidity)
{
      double a = 17.271;
      double b = 237.7;
      double temp = (a * celsius) / (b + celsius) + log(humidity/100);
      double Td = (b * temp) / (a - temp);
      return Td;

}
static int protothread1(struct pt *pt)
{ PT_BEGIN(pt);
while(1)
{ PT_WAIT_UNTIL(pt,mySerial.available());
    while(mySerial.available())
   {
      char bb = (char)mySerial.read();
      if((bb != '\r') && (bb != '\n') ) Str += bb;
      delay(2);
   }
   int strLen = Str.length( );
   if(strLen > 0) Serial.println(Str);   // 送到 Serial Monitor
   if(strLen > 0)
    {
   if(Str.indexOf("+CMGD")!=-1)
   {
       Str = "";return;
   }
   if(Str.indexOf("+CMTI")!=-1)
   {
       getSMS( );
   }else {
      processSMS( ); Str="";
       }
      }
    }
    PT_END(pt);
}
static int protothread2(struct pt *pt)
{ PT_BEGIN(pt);
   while(1)
   { PT_WAIT_THREAD(pt,protothread1);//这里我想法是等第一个线程执行完毕,再显示,不知道这样写对不对//
   LCD();
   }
   PT_END(pt);
}
static struct pt pt1, pt2;
void setup()
{ mySerial.begin(19200);// the GPRS baud rate   
Serial.begin(9600);    // USB to Serial Monitor
Str.reserve(555);// at most 566 char
pinMode(13, OUTPUT);
mySerial.print("AT+CMGF=1\r");// set SMS mode to text
delay(100);
lcd.init();
lcd.backlight();
int chk = DHT11.read(DHT11PIN);
PT_INIT(&pt1);
PT_INIT(&pt2);

}

void loop()
{ protothread1(&pt1);//执行线程1
protothread2(&pt2);
delay(1000);

   

   // .. 其他要做的事
} // loop(
void crlf( ) {   // 送出 <CR><LF> 給 mySerial
mySerial.write(13); mySerial.write(10);
}
void processSMS( )
{ if( Str.indexOf("#13 on")!=-1 )
    {digitalWrite(13,HIGH);
   deleteSMS(lastSMSnumber); delay(333);
   }
if( Str.indexOf("#13 off")!=-1 )
    {
      digitalWrite(13, LOW);
      deleteSMS(lastSMSnumber); delay(222);
    }
    if(Str.indexOf("Survey")!=-1)
    { sendSMS();
      deleteSMS(lastSMSnumber); delay(222);
    }//...處理其他情況的短信
    //...
} //processSMS(
void deleteSMS(int k)
{Str = "";
   mySerial.print("AT+CMGD=");
   mySerial.print(k);
   crlf( );
   ///mySerial.println(",0");// AT+CMGD=38,0 表示刪除第38短信
   delay(138);
}
void getSMS( ){
int cmaPos = Str.indexOf( "," ); // "," 的 position
int dd =cmaPos + 1;
String numSMS = Str.substring(dd);
lastSMSnumber = numSMS.toInt( );// 短信編號
Str = "";// 清除 Str 以收短信 numSMS
mySerial.print("AT+CMGR=");
mySerial.print(numSMS);
crlf( );
delay(88);
}//getSMS(

void sendSMS()
{ mySerial.print("AT+CMGF=1\r");                                                      // AT command to send SMS message
delay(100);
mySerial.println("AT+CMGS=\"+8613905630726\"");   // 送給 +8613905630758                                 // recipient's mobile number, in international format
delay(100);
mySerial.print("Hum = ");
mySerial.print((float)DHT11.humidity, 1);
mySerial.println(" %");
mySerial.print("Tem = ");
mySerial.print((float)DHT11.temperature, 1);
mySerial.println(" oC");
mySerial.println();
delay(100);
mySerial.println((char)26);// End AT command with a ^Z, ASCII code 26
delay(100);
mySerial.println();
}
void LCD()
{   float hum = (float)DHT11.humidity;
      float tem = (float)DHT11.temperature;
      lcd.setCursor(0,0);
      lcd.print("Hum=");
      lcd.print(hum, 1);
      lcd.print(" %");
      lcd.setCursor(0,1);
      lcd.print("Tem=");
      lcd.print(tem, 1);
      lcd.print(" oC");
}
编译没通过,错误信息如下:
Arduino:1.5.5-r2 (Windows XP), 板:"Arduino Uno"

_5555.ino: In function 'int protothread1(pt*)':
_5555:63: error: return-statement with no value, in function returning 'int'

报告将会包含更多的信息
"Show verbose output during compilation"
在 文件>首选项 中启用

另外请教大神们,想要lcd和sim900都能正常运行,应该用什么思路?

xuzhongyu 发表于 2015-3-14 10:42:31

好厉害,看了一遍,慢慢在研究

suoma 发表于 2015-3-26 12:12:51

谢谢分享学习一下

ofourme 发表于 2015-4-6 12:31:35

可以玩一玩

ptlddn 发表于 2015-5-29 09:40:52

感觉上挺不错的

moyuqilin19 发表于 2015-7-22 21:32:49

没有出效果啊,时间间隔到时对的,但是在13脚LED亮是,12脚的LED就停止运行了,这是为什么,这就是多线程要达到的效果吗?还是我那个地方搞错了?

keneng 发表于 2015-11-13 14:32:51

这个需要认真学习的
页: 1 2 3 4 5 [6] 7
查看完整版本: 玩儿大了~给arduino上操作系统了~!