Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "PCF8574.h"
- PCF8574 pcf8574(0x20);
- byte pinWDT = P7;
- byte pinLED = P4;
- bool stateWDT = 0;
- #include "FS.h"
- #include "SD.h"
- #include "SPI.h"
- SPIClass spiSD(HSPI);
- #define SD_CS 14
- #define SDSPEED 27000000
- File root;
- unsigned long cur_time, old_time ;
- bool stateLed = 0;
- const byte wdtPin = 12;
- const byte ledPin = 13;
- bool wdtState = LOW;
- bool ledState = LOW;
- void setup() {
- Serial.begin(115200);
- Serial.println("init pcf: ");
- pcf8574.pinMode(pinWDT, OUTPUT);
- pcf8574.pinMode(pinLED, OUTPUT);
- if (pcf8574.begin()) {
- Serial.println("OK");
- } else {
- Serial.println("KO");
- }
- delay(100);
- spiSD.begin(12, 2, 15, SD_CS); //SCK,MISO,MOSI,ss
- while (!SD.begin( SD_CS, spiSD, SDSPEED)) {
- // if(!SD.begin()){
- Serial.println("Card Mount Failed");
- delay(1000);
- }
- Serial.println("found SD card");
- root = SD.open("/");
- printDirectory(root, 0);
- Serial.println("SD card Done");
- }
- void loop() {
- cur_time = millis();
- if (cur_time - old_time >= 1000) {
- Serial.println("loop function");
- seed_wdt();
- old_time = cur_time;
- }
- }
- void printDirectory(File dir, int numTabs) {
- while (true) {
- File entry = dir.openNextFile();
- if (! entry) {
- // no more files
- break;
- }
- for (uint8_t i = 0; i < numTabs; i++) {
- Serial.print('\t');
- }
- Serial.print(entry.name());
- if (entry.isDirectory()) {
- Serial.println("/");
- printDirectory(entry, numTabs + 1);
- } else {
- // files have sizes, directories do not
- Serial.print("\t\t");
- Serial.println(entry.size(), DEC);
- }
- entry.close();
- }
- }
- void seed_wdt() {
- stateWDT = !stateWDT;
- pcf8574.digitalWrite(pinWDT, stateWDT);
- pcf8574.digitalWrite(pinLED, stateWDT);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement