Hi Forum,
I am making a robot that is designed to tweet a String about Mao everytime it turns. I have it situated out into three files, a main file (tweeting) a file that includes all my twitter security codes (not posting that ) and one with functions to drive the robot. I have not completely finished but I have run into a problem. I ran out of memory. It says the following:
Sketch uses 15,056 bytes (52%) of program storage space. Maximum is 28,672 bytes.
Global variables use 2,836 bytes (110%) of dynamic memory, leaving -276 bytes for local variables. Maximum is 2,560 bytes.
processing.app.debug.RunnerException: Not enough memory; see http://www.arduino.cc/en/Guide/Troubleshooting#size for tips on reducing your footprint.
at processing.app.Sketch.size(Sketch.java:1680)
at processing.app.Sketch.build(Sketch.java:1590)
at processing.app.Sketch.build(Sketch.java:1509)
at processing.app.Editor$DefaultRunHandler.run(Editor.java:1915)
at java.lang.Thread.run(Thread.java:745)
This leads me to believe that the many #define statements in the beginning is taking up all the space but I thought that #define takes no memory. Also, I have a 32GB micro-SD card in the Yún. Why do I have so little storage. The code is below. PLEASE RESPONFQUICKLY THIS IS DUE IN A COUPLE OF HOURS!!!
Main File
#include <Temboo.h>
#include <Bridge.h>
#include "TembooAccount.h" // contains Temboo account information
//conatains functions to drive robot
int numRuns = 1; // execution count, so this sketch doesn't run forever
int maxRuns = 1; // the max number of times the Twitter Update Choreo should run
int quoteCounter; //make a counter for the quotes
int motorCounter; //make a counter for the motor
//declare the tweets
#define tweet1 "1949 - Mao becomes Chairman of China"
#define tweet2 "1949 Foreign Affairs - Mao gets Stalin to sign a treaty for economic aid"
#define tweet3 "1956 - Culture - Mao ecourages 'a hundred flowers to bloom', telling intellectuals to speak out"
#define tweet4 "Mao then targetted the imtellectuals who had spoken out for improvement"
#define tweet5 "1958 - Mao launchs The #Great #Leap #Forward"
#define tweet6 "He encouraged people to set up 'people's communes' telling them to disolve private property"
#define tweet7 "People did not have resources or administration to manage such large social units"
#define tweet8 "In an effort to please Mao party officials left very little grain for people, most of it sent to the governemnt"
#define tweet9 "'Backyard steel' created in an attempt to rapidly industrialize China was useless and consumed rescources."
#define tweet10 "The result was economic disaster"
#define tweet11 "1959 - Mao realises change is needed."
#define tweet12 "1966 - Culture - The Great Proletariat #Cultural #Revolution"
#define tweet13 "Mao purged many officials whom he doubted to have loyalty."
#define tweet14 "Called for students to become 'Red Guards' an organized group of Mao followers who act as his 'civilian police force'"
#define tweet15 "Red Guards rampaged through cities to destroy fourolds - old culture, habits, beliefs and traditions"
#define tweet16 "Red Guards attacjed and humiliated people from a 'bad class status' either intellectuals or those from a wealthy family"
#define tweet17 "This created great chaos, violence, injury and death"
#define tweet18 "1966 - Mao Zhuxi Yulu or the Sayings of Mao, often known as the #Little_Red_Book, was published"
#define tweet19 "August 1966 - Culture - Lao She, a famous plaright is beaten to death by Red Guards"
#define tweet20 "1972 - Foreign Affairs - Nixon Visits China"
#define tweet21 "Mao is able to part differences with capiltalists to his benefit"
#define tweet22 "US agrees to aid China if Taiwan(the nationalists) tries to take China"
#define tweet23 "US used to support nationalists, Mao made China a more valuable ally"
#define tweet24 "Culture -'Model Dramas' proposed, plays that reflect class struggle and revolutionary action. #propaganda"
#define tweet25 "People of 'bad class status' sent to work in fields or imprisoned"
#define tweet26 "The end result: 1.5 million murdered, a million more tortured, imprisoned, humiliated and robbed of property."
void setup() {
Serial.begin(9600);
delay(4000);
while(!Serial);
Bridge.begin();
setupRobot();
}
void loop(){
if(turnAround){
if (numRuns <= maxRuns) {
quoteCounter++;
// define the text of the tweet we want to send
String tweetText;
TembooChoreo StatusesUpdateChoreo;
// invoke the Temboo client
// NOTE that the client must be reinvoked, and repopulated with
// appropriate arguments, each time its run() method is called.
StatusesUpdateChoreo.begin();
// set Temboo account credentials
StatusesUpdateChoreo.setAccountName(TEMBOO_ACCOUNT);
StatusesUpdateChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
StatusesUpdateChoreo.setAppKey(TEMBOO_APP_KEY);
// identify the Temboo Library choreo to run (Twitter > Tweets > StatusesUpdate)
StatusesUpdateChoreo.setChoreo("/Library/Twitter/Tweets/StatusesUpdate");
// add the Twitter account information
StatusesUpdateChoreo.addInput("AccessToken", TWITTER_ACCESS_TOKEN);
StatusesUpdateChoreo.addInput("AccessTokenSecret", TWITTER_ACCESS_TOKEN_SECRET);
StatusesUpdateChoreo.addInput("ConsumerKey", TWITTER_API_KEY);
StatusesUpdateChoreo.addInput("ConsumerSecret", TWITTER_API_SECRET);
//switch statement evaluates which tweet to tweet
switch(quoteCounter){
case 1:
tweetText = tweet1;
break;
case 2:
tweetText = tweet2;
break;
case 3:
tweetText = tweet3;
break;
case 4:
tweetText = tweet4;
break;
case 5:
tweetText = tweet5;
break;
case 6:
tweetText = tweet6;
break;
case 7:
tweetText = tweet7;
break;
case 8:
tweetText = tweet8;
break;
case 9:
tweetText = tweet9;
break;
case 10:
tweetText = tweet10;
break;
case 11:
tweetText = tweet11;
break;
case 12:
tweetText = tweet12;\
break;
case 13:
tweetText = tweet13;
break;
case 14:
tweetText = tweet14;
break;
case 15:
tweetText = tweet15;
break;
case 16:
tweetText = tweet16;
break;
case 17:
tweetText = tweet17;
break;
case 18:
tweetText = tweet18;
break;
case 19:
tweetText = tweet19;
break;
case 20:
tweetText = tweet20;
break;
case 21:
tweetText = tweet21;
break;
case 22:
tweetText = tweet22;
break;
case 23:
tweetText = tweet23;
break;
case 24:
tweetText = tweet24;
break;
case 25:
tweetText = tweet25;
break;
case 26:
tweetText = tweet26;
break;
}
// and the tweet we want to send
StatusesUpdateChoreo.addInput("StatusUpdate", tweetText);
// tell the Process to run and wait for the results. The
// return code (returnCode) will tell us whether the Temboo client
// was able to send our request to the Temboo servers
unsigned int returnCode = StatusesUpdateChoreo.run();
// a return code of zero (0) means everything worked
/* if (returnCode == 0) {
Serial.println("Success! Tweet sent!");
} else {
// a non-zero return code means there was an error
// read and print the error message
while (StatusesUpdateChoreo.available()) {
char c = StatusesUpdateChoreo.read();
Serial.print(c);
}
}
*/
StatusesUpdateChoreo.close();
// do nothing for the next 90 seconds
}
}
Robot File
#define aDirection 12 //define the pins
#define bDirection 13
#define aSpeed 3
#define bSpeed 11
#define aBrake 9
#define bBrake 8
void moveForward(){
digitalWrite(aBrake, LOW); //disable brakes
digitalWrite(bBrake, LOW);
digitalWrite(aSpeed, 100); //set speed to 100
digitalWrite(bSpeed, 100);
digitalWrite(aDirection, HIGH); //set direction to forward
digitalWrite(bDirection, HIGH);
}
void turnAround(){
digitalWrite(aDirection, LOW);
digitalWrite(bDirection, HIGH);
digitalWrite(aSpeed, 100);
digitalWrite(bSpeed, 100);
}
/*void setupRobot(){
pinMode(aBrake, OUTPUT);
pinMode(bBrake, OUTPUT);
pinMode(aDirection, OUTPUT);
pinMode(bDirection, OUTPUT);
pinMode(aSpeed, OUTPUT);
pinMode(bSpeed, OUTPUT);
}
*/