Arduino應用

出自TSK WIKI
於 2019年5月22日 (三) 13:39 由 Stanleyliu​(留言 | 貢獻) 所做的修訂 (→老化箱校正)
跳至導覽 跳至搜尋

老化箱校正

<C>

  1. include <SPI.h>
  2. include <SD.h>
  3. include "Max6675.h"

File myFile; // Max6675 module: SO on pin #8, SS on pin #9, CSK on pin #10 of Arduino UNO // Other pins are capable to run this library, as long as digitalRead works on SO, // and digitalWrite works on SS and CSK Max6675 ts(5, 6, 7);

void setup() {

 Serial.begin(9600);
 while (!Serial) {    // 等待串列埠連線
 }

 Serial.print("Initializing SD card...");
 if (!SD.begin(4)) {
   Serial.println("Fail!");
   return;
 }
 Serial.println("Success!");
 
ts.setOffset(0);

}

void loop() {

float t= ts.getCelsius();
String strT= String("")+t+","+millis();
Serial.println(strT);
myFile = SD.open("card.txt", FILE_WRITE); 
myFile.println(strT);
myFile.close();                               // 關閉檔案
Serial.println("Completed!"); 
delay(10000);

} </c>

  • 增加看板

<c>

  1. include <SPI.h>
  2. include <RGBmatrixPanel.h>
  3. include "Max6675.h"
  1. define CLK 8 // USE THIS ON ARDUINO UNO, ADAFRUIT METRO M0, etc.

//#define CLK A4 // USE THIS ON METRO M4 (not M0) //#define CLK 11 // USE THIS ON ARDUINO MEGA

  1. define OE 9
  2. define LAT 10
  3. define A A0
  4. define B A1
  5. define C A2

RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, false); Max6675 ts(A3,A4,A5);

void setup() {

 Serial.begin(9600);
 matrix.begin();
 ts.setOffset(0);
 matrix.fillScreen(matrix.Color333(0, 0, 0));
 matrix.setCursor(1, 0);  // start at top left, with one pixel of spacing
 matrix.setTextSize(1);   // size 1 == 8 pixels high
  matrix.setTextColor(matrix.Color333(7,0,0));// print each letter with a rainbow color

}

void loop() {

float t= ts.getCelsius();
String strT= String("")+t+","+millis();
Serial.println(strT);
matrix.fillScreen(matrix.Color333(0, 0, 0));
matrix.setCursor(0, 0);
matrix.setTextColor(matrix.Color333(7,0,0));
matrix.print(t);
matrix.setCursor(0, 9);
matrix.setTextColor(matrix.Color333(0,7,0));
matrix.print(millis()/1000);
                              // 關閉檔案
Serial.println("Completed!"); 
delay(10000);

} </c>