Post by hiram on Mar 31, 2015 10:33:03 GMT -8
I try to show text and one picture in the GD at the same time, when i do it alone without any SPI device connected works fine, but when i try with another SPI device don't show the picture or the text this is my code.
#include <SPI.h>
#include <MFRC522.h>
#include <EEPROM.h>
#include <GD2.h>
#define RST_PIN 7 //
#define SS_PIN 6 //
#define GPU_PIN 8 // Gameduino GPU
#define SD_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
void setup() {
Serial.begin(9600);
SPI.begin(); // Init SPI bus
pinMode(SS_PIN, OUTPUT); // off SS_PIN reader
digitalWrite(SS_PIN, HIGH);
pinMode(GPU_PIN, OUTPUT); // on GPU_PIN GD
digitalWrite(GPU_PIN, LOW);
//pinMode(SD_PIN, OUTPUT);
// Initialize GD2
GD.begin(0);
Serial.println("Init Screen");
delay(100);
GD.__end();
// Initialize Reader
Serial.println("Init Reader");
mfrc522.PCD_Init();
delay(100);
GD.resume();
}
void loop(){
GD.resume();
GD.ClearColorRGB(0x007070);
GD.Clear();
const char *msg = "Test two";
GD.cmd_text(240, 136, 31, OPT_CENTER, msg);
GD.swap();
GD.finish();
GD.__end();
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;
}
if ( ! mfrc522.PICC_ReadCardSerial()) {
return;
}
dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
Serial.println(" Done ");
delay(2000);
GD.__end();
mfrc522.PICC_HaltA(); // Halt PICC
mfrc522.PCD_StopCrypto1(); // Stop encryption on PCD
}
void dump_byte_array(byte *buffer, byte bufferSize) {
/*
GD.resume();
GD.ClearColorRGB(0xff3333);
GD.Clear();
GD.cmd_text(240, 136, 31, OPT_CENTER, "Solo texto");
GD.swap();
GD.finish();
GD.flush();
delay(500);
*/
//GD.__end();
GD.resume();
GD.Clear();
GD.cmd_loadimage(0, 0);
GD.load("imagen.jpg");
GD.Begin(BITMAPS);
GD.BitmapSize(NEAREST, BORDER, BORDER, 480, 272);
GD.Vertex2ii(0, 0);
// digitalWrite(GPU_PIN, LOW);
GD.ClearColorRGB(0xff3333);
GD.Clear();
GD.cmd_text(350, 136, 31, OPT_CENTER, "test with image");
GD.swap();
GD.finish();
delay(500);
}