這份技術文件對直接使用 Arduino 寫系統大程式的朋友應該會有些幫助,因為之前設計 ROSA 時把 RAM 寫爆掉,因此我需要重新思考,如果想將 mBot 含入 ROSA 功能,那麼 Arduino 還剩多少記憶空間可以給 ROSA 使用?
因此,我計算一下 Arduino 常用程式庫大約占用記憶體空間狀況如下:
Function
|
Code
|
ROM (bytes)
|
RAM (bytes)
|
None
|
void setup() {}
void loop() {}
|
450
|
9
|
Serial
|
void setup() {
byte i;
Serial.begin(115200);
Serial.println("");
i = Serial.read();
}
void loop() {}
|
1824
|
184
|
Serial
|
byte i;
void setup() {
Serial.begin(115200);
Serial.println("");
i = Serial.read();
}
void loop() {}
|
1830
|
185
|
Software Serial
|
#include "softwareserial.h"
SoftwareSerial BT(11,12);
void setup() {
byte i;
BT.begin(115200);
BT.println("");
i = BT.read();
}
void loop() {}
|
2712
|
126
|
Software Serial
|
#include "softwareserial .h"
SoftwareSerial BT(11,12);
byte i;
void setup() {
BT.begin(115200);
BT.println("");
i = BT.read();
}
void loop() {}
|
2718
|
127
|
I2C
|
#include "wire.h"
void setup() {
Wire.begin();
Wire.onReceive(receiveEvent);
}
void loop() {
Wire.beginTransmission(3);
Wire.write(0);
Wire.endTransmission();
}
void receiveEvent(int numBytes){
while(Wire.available()){
char c = Wire.read();
}
}
|
2184
|
219
|
Buzzer
|
void setup() {
pinMode(8, OUTPUT);
}
void loop() {
tone(8, 220, 10);
}
|
2394
|
32
|
IR
|
#include "IRremote.h"
unsigned int btnRec[] = {9100};
IRrecv irrecv(2);
IRsend irsend;
decode_results results;
void setup() {
irrecv.enableIRIn();
}
void loop(){
irsend.sendRaw(btnRec, 1, 38);
if (irrecv.decode(&results)){
irrecv.resume();
}
}
|
2872
|
233+66
|
UltraSound
|
unsigned long ping() {
digitalWrite(17,HIGH);
delayMicroseconds(5);
digitalWrite(17, LOW);
return pulseIn(16, HIGH);
}
void setup() {
pinMode(17, OUTPUT);
pinMode(16, INPUT);
}
void loop() {
unsigned long d;
d = ping() / 50;
}
|
1238
|
9
|
LED
|
#include "adafruit_neopixel .h"
Adafruit_NeoPixel strip = Adafruit_NeoPixel(2, 13, NEO_GRB + NEO_KHZ800);
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
colorWipe(strip.Color(255, 0, 0), 50);
}
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}
|
2622
|
35
|
PWM
|
void setup(){
pinMode(5, OUTPUT);
}
void loop() {
analogWrite(5, 128);
}
|
1060
|
9
|
D out
|
void setup(){
pinMode(4, OUTPUT);
}
void loop() {
digitalWrite(4, HIGH);
}
|
846
|
9
|
A in
|
void setup() {}
void loop() {
int val0;
va0l = analogRead(A0);
}
|
536
|
11
|
D in
|
void setup() {}
void loop() {
boolean val;
val = digitalRead(9);
}
|
688
|
9
|
Delay
|
void setup() {}
void loop() {
delay(1000);
}
|
612
|
9
|
目前估計,Arduino 基本程式庫約佔 10 kB ROM 及 600 Bytes RAM,剩餘空間不多繼續努力。
沒有留言:
張貼留言