/*
SD card read/write
This example shows how to read and write data to and from an SD card file
The circuit:
SD card attached to SPI bus as follows:
** MOSI - pin 11
** MISO - pin 12
** CLK - pin 13
** CS - pin 4 (for MKRZero SD: SDCARD_SS_PIN)
*/
#include <SPI.h>
#include <SD.h>
#define redPin1 3
#define bluePin1 0
#define greenPin1 2
#define redPin2 5
#define bluePin2 6
#define greenPin2 7
#define redPin3 8
#define bluePin3 9
#define greenPin3 10
char testArray[30];
int testArray2[300] = {5, 10, 15, 20};
File myFile;
//create array of LEDs
byte rgbPinArray[] = {bluePin1, greenPin1, redPin1, bluePin2, redPin2, greenPin2, bluePin3, greenPin3, redPin3};
int rgbPinNumber = sizeof(rgbPinArray) / sizeof(rgbPinArray[0]);
void setColor(int redValue, int greenValue, int blueValue) {
analogWrite(redPin1, redValue);
analogWrite(greenPin1, greenValue);
analogWrite(bluePin1, blueValue);
}
//initialize all the pins
void initPins() {
for (int i = 0; i < rgbPinNumber; i++) {
pinMode(rgbPinArray[i], OUTPUT);
}
}
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
initPins();
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.print("Initializing SD card...");
if (!SD.begin(4)) {
Serial.println("initialization failed!");
while (1);
}
Serial.println("initialization done.");
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
//myFile = SD.open("test.txt");
myFile = SD.open("test.txt");
// if the file opened okay, write to it:
if(myFile)
{
Serial.println("test.txt");
while(myFile.available())
{
testArray[10] = myFile.read();
}
myFile.close();
}
else
{
Serial.println("File does not exist or named wrong");
}
}
void loop() {
// nothing happens after setup
//analogWrite(redPin1, 1);
analogWrite(greenPin1, 255);
}