Robofun 機器人論壇

 找回密碼
 申請會員
搜索
熱搜: 活動 交友 discuz
查看: 2388|回復: 7

progmem的問題

[複製鏈接]
發表於 2017-4-24 15:45:32 | 顯示全部樓層 |閱讀模式
能否把這段用成陣列

static unsigned int one[71]   = {232, 888, 232, 2244, 220, 756, 228, 2788, 232, 1292, 224, 1300, 224, 1432, 232, 1836, 224, 14268, 228, 888, 284, 2596, 224, 756, 228, 748, 232, 748, 224, 888, 232, 748, 224, 752, 232, 15412, 228, 888, 232, 2244, 224, 752, 232, 2788, 232, 1288, 228, 1296, 228, 1428, 232, 1836, 224, 14268, 232, 884, 220, 1572, 228, 1840, 228, 752, 220, 756, 228, 884, 224, 756, 228, 748, 232};  

但必須保留static的部分 也不行用const static
這樣好像紅外線發射出去時是無效的
發表於 2017-4-24 17:47:36 來自手機 | 顯示全部樓層
本帖最後由 超新手 於 2017-4-25 08:02 編輯

如果這個 static unsigned int one[71]   不叫陣列,那什麼叫做陣列?
 樓主| 發表於 2017-4-25 15:57:21 | 顯示全部樓層
我想使用progmem
發表於 2017-4-25 17:47:12 | 顯示全部樓層
只能 const static PROGMEM  unsigned int one[71]   =
READ 時, 一定要用, pgm_read_word_near...去讀, 否則會錯
只是好奇, 為什麼一定要用 PROGMEM
如果用
const  static unsigned int one[71]  = {....};
或是
static unsigned int one[71]  = {....};
效果應該差不多, 而且限制較少
 樓主| 發表於 2017-4-25 18:03:56 | 顯示全部樓層
sram不夠
有試過const static了  紅外線沒有發射出去

我想做的是
http://smallbeetw.blogspot.tw/search/label/%E5%87%B1%E6%93%98
這篇文章的程式
發表於 2017-4-26 08:45:19 | 顯示全部樓層
本帖最後由 超新手 於 2017-4-26 08:46 編輯

我試過了, 不管有沒有加 static, const, 都有輸出, 沒問題!
你是指, "不加 const 就有輸出, 但加了 const 就沒輸出嗎?"
還是你量錯腳?
因為每個機種的輸出並不相同, 像 UNO 是 3, MEGA 是 9....

#include <IRremote.h>
IRsend irsend;
const unsigned int sendRawCodes[71]={...};
void setup() {
  Serial.begin(9600);
}
void loop() {
  irsend.sendRaw(sendRawCodes,71,38);
  Serial.println("Sent raw");
  delay(500);
}
 樓主| 發表於 2017-4-26 12:02:44 | 顯示全部樓層
const unsigned int sendRawCodes[71]={...};這段還要加上PROGMEM
不然SRAM會不夠用
但加了之後 其他紅外線發射出去有電視都有收到
但不知道為甚麼發射到機上盒的紅外線就都沒反應
發表於 2017-4-26 12:16:25 | 顯示全部樓層
本帖最後由 超新手 於 2017-4-26 14:09 編輯

只要宣告成 CONST 的陣列, 就不會用到 SRAM
const unsigned int sendRawCodes[71]


如果要用 PROGMEM 也可以. 只是沒必要
而且你程式要改, 必須要呼叫 pgm_read_word_near 之類的程式去讀值
不可直接用原來程式
而且使用時, 還是要用 SRAM 去接
您需要登錄後才可以回帖 登錄 | 申請會員

本版積分規則

小黑屋|手機版|Archiver|機器人論壇 from 2005.07

GMT+8, 2024-3-29 21:49 , Processed in 0.172426 second(s), 6 queries , Apc On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表