We have a big (important) question:
Maybe you can help;)
We have the error:
sketch_dec02a:41: error: expected constructor, destructor, or type conversion before '.' token
Here is our program:
#include <Shieldbot.h>
#include <SD.h>
#include <SPI.h>
#include "TFTv2.h"
File bmpDatei;
File bmpFile;
unsigned char saved_spimode;
int bmpWidth, bmpHeight;
uint8_t bmpDepth, bmpImageoffset;
int SDPin=4;
#define chipSelect 4
Sd2Card card;
SdVolume volume;
SdFile root;
Shieldbot shieldbot = Shieldbot();
int S1,S2,S3,S4,S5;
void setup(){
pinMode(11,INPUT);
pinMode(12,INPUT);
pinMode(13,INPUT);
TFT_CS_HIGH;
pinMode(SDPin,OUTPUT);
digitalWrite(SDPin,HIGH);
Serial.begin(115200);
SPI.begin();
Tft.TFTinit();
DDRB |= 0x04;
card.init(SPI_FULL_SPEED,SDPin);//SPI_QUARTER_SPEED SPI_HALF_SPEED, SPI_FULL_SPEED,
if(!SD.begin(SDPin))//SPI_QUARTER_SPEED,
Serial.println("failed!");
while(1);
}
[color=red] Serial.println("SD OK!");
[/color]
{
Tft.setCol(0,239);
Tft.setPage(0,319);
Tft.sendCMD(0x2c);//start to write to display ram
TFT_BL_ON;
}
void loop(){
S1 = shieldbot.readS1();
S2 = shieldbot.readS2();
S3 = shieldbot.readS3();
S4 = shieldbot.readS4();
S5 = shieldbot.readS5();
Serial.print("S5: ");
Serial.print(S5);
Serial.print(" S4: ");
Serial.print(S4);
Serial.print(" S3: ");
Serial.print(S3);
Serial.print(" S2: ");
Serial.print(S2);
Serial.print(" S1: ");
Serial.print(S1);
Serial.println();
if(S1 == HIGH && S5 == HIGH){
shieldbot.forward();
Serial.println("Forward");
}else if(S1 == LOW && S5 == LOW){
shieldbot.stop();
Serial.println("Stop");
delay(100);
}else if((S1 == LOW) || (S2 == LOW)){
shieldbot.drive(127,-128);
Serial.println("Right");
delay(100);
}else if((S5 == LOW) || (S4 == LOW)){
shieldbot.drive(-128,127);
Serial.println("Left");
delay(100);
char bmpfiles[][18]={
"bmp1.bmp","bmp2.bmp","bmp3.bmp"
};
for(unsigned char i=0;i<3;i++) {
bmpFile = SD.open(bmpfiles[i]);
if (! bmpFile){
Serial.println("didnt find image");
while (1);
}
Tft.setCol(0,239);
Tft.setPage(0,319);
Tft.sendCMD(0x2c);//start to write to display ram
bmpDatei = SD.open("bmp1.bmp");
if (!bmpReadHeader(bmpDatei)){
return;
}
if (! bmpReadHeader(bmpFile)) {
Serial.println("bad bmp");
return;
}
Serial.print("image size ");
Serial.print(bmpWidth, DEC);
Serial.print(", ");
Serial.println(bmpHeight, DEC);
bmpdraw(bmpFile, 0, 0);
bmpFile.close();
delay(1000);
}
bmpdraw(bmpDatei, 0, 0);
bmpDatei.close();
delay(5000);
Tft.setCol(0,239);
Tft.setPage(0,319);
Tft.sendCMD(0x2c);//start to write to display ram
bmpDatei = SD.open("bmp3.bmp");
if (!bmpReadHeader(bmpDatei)){
return;
}
bmpdraw(bmpDatei, 0, 0);
bmpDatei.close();
delay(5000);
}
/*********************************************/
// This procedure reads a bitmap and draws it to the screen
// its sped up by reading many pixels worth of data at a time
// instead of just one pixel at a time. increading the buffer takes
// more RAM but makes the drawing a little faster. 20 pixels' worth
// is probably a good place
#define BUFFPIXEL 20
void bmpdraw(File f, int x, int y){
bmpDatei.seek(bmpImageoffset);
uint32_t time = millis();
uint16_t p;
uint8_t g, b;
int i, j;
uint8_t sdbuffer[3 * BUFFPIXEL]; // 3 * pixels to buffer
uint8_t buffidx = 3*BUFFPIXEL;
for (i=0; i< bmpHeight; i++){
for (j=0; j<bmpWidth; j++){
// read more pixels
if (buffidx >= 3*BUFFPIXEL){
bmpDatei.read(sdbuffer, 3*BUFFPIXEL);
buffidx = 0;
}
b = sdbuffer[buffidx++]; // blue
g = sdbuffer[buffidx++]; // green
p = sdbuffer[buffidx++]; // red
p >>= 3;
p <<= 6;
g >>= 2;
p |= g;
p <<= 5;
b >>= 3;
p |= b;
// write out the 16 bits of color
Tft.sendData(p);
}
}
Serial.print(millis() - time, DEC);
Serial.println(" ms");
}
}
boolean bmpReadHeader(File f) {
// read header
uint32_t tmp;
if (read16(f) != 0x4D42) {
// magic bytes missing
return false;
}
// read file size
tmp = read32(f);
Serial.print("size 0x");
Serial.println(tmp, HEX);
// read and ignore creator bytes
read32(f);
bmpImageoffset = read32(f);
Serial.print("offset ");
Serial.println(bmpImageoffset, DEC);
// read DIB header
tmp = read32(f);
Serial.print("header size ");
Serial.println(tmp, DEC);
bmpWidth = read32(f);
bmpHeight = read32(f);
if (read16(f) != 1)
return false;
bmpDepth = read16(f);
Serial.print("bitdepth ");
Serial.println(bmpDepth, DEC);
if (read32(f) != 0) {
// compression not supported!
return false;
}
Serial.print("compression ");
Serial.println(tmp, DEC);
return true;
}
/*********************************************/
// These read data from the SD card file and convert them to big endian
// (the data is stored in little endian format!)
// LITTLE ENDIAN!
uint16_t read16(File f) {
uint16_t d;
uint8_t b;
b = f.read();
d = f.read();
d <<= 8;
d |= b;
return d;
}
// LITTLE ENDIAN!
uint32_t read32(File f) {
uint32_t d;
uint16_t b;
b = read16(f);
d = read16(f);
d <<= 16;
d |= b;
return d;
}
This program is for a linefollowing shieldbot and a display with pictures.
PLEEEEEEEEEEEEEEASE help us!!
It's a school-project.
We're one unit!
[/i]
Moderator: added [code]...[/code]
tags to show code properly.