Hi ,
I'm trying to run a code which complies and uploads to the arduino, but the serial monitor (which should at least print the SD card being initialized) remains blank and the LED on Pin 13 turns on by itself. Is the program crashing ?
//using namespace std;
#include <SD.h>#define SCALE_MAP 2
#define GRID_ROWS 96
#define GRID_COLS 50
//File myFile;
//
//char fileName[12] = "map.bmp";
#define SDchipSelect 10 //chip select for SD card --53 on mega, 10 on 328
#define WSchipSelect 4 //chip select for WS2801// You can change this to use dynamic memory, if you like.
float gridMap[GRID_ROWS][GRID_COLS];/*************************************************************************
- Function inputMap converts the input map information into an *
- initial occupancy grid, which is stored in gridMap. *
- (Here, the "output" parameter says whether to print out the scaled *
- map; output = 1 ==> yes, print; output = 0 ==> no, don't print.) *
*************************************************************************/void setup()
{
//randomSeed(analogRead(0));
// Serial.begin(9600);
Serial.begin(9600);
Serial.println();
Serial.println("Start");Serial.print("Initializing SD card...");
// make sure that the default chip select pin is set to
// output, even if you don't use it:
//pinMode(SDchipSelect, OUTPUT); //required for SPI to work
pinMode(WSchipSelect, OUTPUT); //required for WS2801 'spi' to work
if (!SD.begin(SDchipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
return;
}
Serial.println("card initialized.");
inputMap();}
void loop() {}
//void inputMap(int output)
void inputMap()
{
int i, j, m, n;
char inputLine1[40], nextChar;
int width, height, maxVal;
#include <SD.h>
File myFile;
myFile = SD.open("map.bmp", FILE_READ);/* Initialize map to 0's, meaning all free space */
for (m=0; m<GRID_ROWS; m++)
for (n=0; n<GRID_COLS; n++)
gridMap[m][n] = 0.0;/* Read past first line /
//inFile.getline(inputLine1,80);
myFile.read(inputLine1,40);
/ Read in width, height, maxVal */
myFile >> width >> height >> maxVal;
Serial.print(width); //Width
Serial.print(height); //Height
Serial.print("\t"); //tab/* Read in map; /
for (i=0; i<height; i++)
for (j=0; j<width; j++) {
myFile >> nextChar;
if (!nextChar)
gridMap[i/SCALE_MAP][j/SCALE_MAP] = 1.0;
}
Serial.print("Map input complete");
}
//
// if (output) {
// ofstream outFile("scaled_hospital_section.pnm");
// outFile << inputLine1 << endl;
// outFile << width/SCALE_MAP << " " << height/SCALE_MAP << endl
// << maxVal << endl;
//
// for (i=0; i<height/SCALE_MAP; i++)
// for (j=0; j<width/SCALE_MAP; j++) {
// if (gridMap[j] == 1.0)*
// outFile << (char) 0;
// else
// outFile << (char) -1;
// }
// cout << "Scaled map output to file.\n";
// }
//}
//
//int main(int argc, char *argv[])
//{
// inputMap(1); // Here, '1' means to print out the scaled map to a file;
// // If you don't want the printout, pass a parameter of '0'.
//}
[/quote]