极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

楼主: Malc

玩儿大了~给arduino上操作系统了~!

  [复制链接]
发表于 2014-7-23 18:35:41 | 显示全部楼层
PT库不可以用delay,可以用delayMicroseconds吗?好像这也不行。
回复 支持 反对

使用道具 举报

发表于 2014-7-23 18:38:07 | 显示全部楼层
我如果同时用pt,又用pwm,又用定时器1或2,这一定会有影响吧。大神,求使用具体条件。
回复 支持 反对

使用道具 举报

发表于 2014-7-25 15:23:04 | 显示全部楼层
记号,留待以后学习。
回复 支持 反对

使用道具 举报

发表于 2014-7-30 23:19:29 | 显示全部楼层
是不是每个时间片断的长度要比一个线程的执行时间不短?
回复 支持 反对

使用道具 举报

发表于 2014-9-1 16:19:24 | 显示全部楼层

MARK一下
回复 支持 反对

使用道具 举报

发表于 2014-11-7 09:50:26 | 显示全部楼层
switch magic~~~ nice~~
回复 支持 反对

使用道具 举报

发表于 2014-11-29 13:17:59 | 显示全部楼层
这个不错可以用来做ArduinoPLC的操作系统了!!
回复 支持 反对

使用道具 举报

发表于 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
回复 支持 反对

使用道具 举报

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

  13. int flag = 0;
  14. double Fahrenheit(double celsius)
  15. {
  16.         return 1.8 * celsius + 32;
  17. }    //摄氏温度度转化为华氏温度
  18.   
  19. double Kelvin(double celsius)
  20. {
  21.         return celsius + 273.15;
  22. }     //摄氏温度转化为开氏温度
  23.   
  24. double dewPoint(double celsius, double humidity)
  25. {
  26.         double A0= 373.15/(273.15 + celsius);
  27.         double SUM = -7.90298 * (A0-1);
  28.         SUM += 5.02808 * log10(A0);
  29.         SUM += -1.3816e-7 * (pow(10, (11.344*(1-1/A0)))-1) ;
  30.         SUM += 8.1328e-3 * (pow(10,(-3.49149*(A0-1)))-1) ;
  31.         SUM += log10(1013.246);
  32.         double VP = pow(10, SUM-3) * humidity;
  33.         double T = log(VP/0.61078);   // temp var
  34.         return (241.88 * T) / (17.558-T);
  35. }
  36.   
  37. double dewPointFast(double celsius, double humidity)
  38. {
  39.         double a = 17.271;
  40.         double b = 237.7;
  41.         double temp = (a * celsius) / (b + celsius) + log(humidity/100);
  42.         double Td = (b * temp) / (a - temp);
  43.         return Td;

  44. }
  45. static int protothread1(struct pt *pt)
  46. { PT_BEGIN(pt);
  47.   while(1)
  48. { PT_WAIT_UNTIL(pt,mySerial.available());
  49.     while(mySerial.available())
  50.      {
  51.       char bb = (char)mySerial.read();
  52.       if((bb != '\r') && (bb != '\n') ) Str += bb;
  53.       delay(2);
  54.      }
  55.    int strLen = Str.length( );
  56.    if(strLen > 0) Serial.println(Str);   // 送到 Serial Monitor
  57.    if(strLen > 0)
  58.     {
  59.      if(Str.indexOf("+CMGD")!=-1)
  60.      {
  61.        Str = "";  return;
  62.      }
  63.      if(Str.indexOf("+CMTI")!=-1)
  64.      {
  65.        getSMS( );
  66.      }else {
  67.         processSMS( ); Str="";
  68.        }
  69.       }
  70.     }
  71.     PT_END(pt);
  72. }  
  73. static int protothread2(struct pt *pt)
  74. { PT_BEGIN(pt);
  75.    while(1)
  76.    { PT_WAIT_THREAD(pt,protothread1);[color=Red]//  这里我想法是等第一个线程执行完毕,再显示,不知道这样写对不对//[/color]
  77.      LCD();
  78.    }
  79.    PT_END(pt);
  80. }  
  81. static struct pt pt1, pt2;
  82. void setup()
  83. { mySerial.begin(19200);  // the GPRS baud rate   
  84.   Serial.begin(9600);    // USB to Serial Monitor
  85.   Str.reserve(555);  // at most 566 char
  86.   pinMode(13, OUTPUT);
  87.   mySerial.print("AT+CMGF=1\r");  // set SMS mode to text
  88.   delay(100);
  89.   lcd.init();
  90.   lcd.backlight();
  91.   int chk = DHT11.read(DHT11PIN);
  92.   PT_INIT(&pt1);
  93.   PT_INIT(&pt2);
  94.   
  95. }
  96.   
  97. void loop()
  98. { protothread1(&pt1);  //执行线程1
  99.   protothread2(&pt2);
  100.   delay(1000);
  101.   
  102.    
  103.   
  104.    // .. 其他要做的事
  105. } // loop(
  106. void crlf( ) {   // 送出 <CR><LF> 給 mySerial
  107.   mySerial.write(13); mySerial.write(10);
  108. }
  109. void processSMS( )
  110. { if( Str.indexOf("#13 on")!=-1 )
  111.     {digitalWrite(13,HIGH);
  112.      deleteSMS(lastSMSnumber); delay(333);
  113.      }
  114.   if( Str.indexOf("#13 off")!=-1 )
  115.     {
  116.       digitalWrite(13, LOW);
  117.       deleteSMS(lastSMSnumber); delay(222);
  118.     }
  119.     if(Str.indexOf("Survey")!=-1)
  120.     { sendSMS();
  121.       deleteSMS(lastSMSnumber); delay(222);
  122.     }//...處理其他情況的短信
  123.     //...
  124. } //processSMS(
  125. void deleteSMS(int k)
  126.   {  Str = "";
  127.      mySerial.print("AT+CMGD=");  
  128.      mySerial.print(k);  
  129.      crlf( );
  130.      ///mySerial.println(",0");  // AT+CMGD=38,0 表示刪除第38短信
  131.      delay(138);
  132.   }
  133. void getSMS( ){
  134.   int cmaPos = Str.indexOf( "," ); // "," 的 position
  135.   int dd =cmaPos + 1;
  136.   String numSMS = Str.substring(dd);
  137.   lastSMSnumber = numSMS.toInt( );  // 短信編號
  138.   Str = "";  // 清除 Str 以收短信 numSMS
  139.   mySerial.print("AT+CMGR=");
  140.   mySerial.print(numSMS);
  141.   crlf( );
  142.   delay(88);
  143.   }//getSMS(

  144. void sendSMS()
  145. { mySerial.print("AT+CMGF=1\r");                                                        // AT command to send SMS message
  146.   delay(100);
  147.   mySerial.println("AT+CMGS="+8613905630726"");   // 送給 +8613905630758                                 // recipient's mobile number, in international format
  148.   delay(100);
  149.   mySerial.print("Hum = ");
  150.   mySerial.print((float)DHT11.humidity, 1);
  151.   mySerial.println(" %");
  152.   mySerial.print("Tem = ");
  153.   mySerial.print((float)DHT11.temperature, 1);
  154.   mySerial.println(" oC");
  155.   mySerial.println();
  156.   delay(100);
  157.   mySerial.println((char)26);  // End AT command with a ^Z, ASCII code 26
  158.   delay(100);
  159.   mySerial.println();
  160. }
  161. void LCD()
  162. {     float hum = (float)DHT11.humidity;
  163.       float tem = (float)DHT11.temperature;
  164.       lcd.setCursor(0,0);
  165.       lcd.print("Hum=");
  166.       lcd.print(hum, 1);
  167.       lcd.print(" %");
  168.       lcd.setCursor(0,1);
  169.       lcd.print("Tem=");
  170.       lcd.print(tem, 1);
  171.       lcd.print(" oC");
  172. }  
复制代码
编译没通过,错误信息如下:
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都能正常运行,应该用什么思路?
回复 支持 反对

使用道具 举报

发表于 2015-3-14 10:42:31 | 显示全部楼层
好厉害,看了一遍,慢慢在研究
回复 支持 反对

使用道具 举报

发表于 2015-3-26 12:12:51 | 显示全部楼层
谢谢分享学习一下
回复 支持 反对

使用道具 举报

发表于 2015-4-6 12:31:35 来自手机 | 显示全部楼层
可以玩一玩
回复 支持 反对

使用道具 举报

发表于 2015-5-29 09:40:52 | 显示全部楼层
感觉上挺不错的
回复 支持 反对

使用道具 举报

发表于 2015-7-22 21:32:49 | 显示全部楼层
没有出效果啊,时间间隔到时对的,但是在13脚LED亮是,12脚的LED就停止运行了,这是为什么,这就是多线程要达到的效果吗?还是我那个地方搞错了?
回复 支持 反对

使用道具 举报

发表于 2015-11-13 14:32:51 | 显示全部楼层
这个需要认真学习的
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-4-16 19:57 , Processed in 0.045995 second(s), 30 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

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