驗菌&螢光兩用儀 組裝
一機兩用的儀器,快來了解如何組裝吧!
所需材料:
最小系統電路板:STM32F103C8T6 Blue Pill板
麵包板電源:3.3V 5V 12V多路输出
光源:LED • 600nm-Orange、UV-LED 365nm
光偵測器:型號 TSL-2561傳感器
光源選擇指示燈:3色LED模組-RGB
數值顯示器:0.96寸 藍色IIC通信小OLED顯示屏模塊
上層
---------------------------------------------------------------------
操作 第一行之L值為未換算前的穿透係數。
按下2可記錄空白組數值(螢幕顯示L0),按3可記錄待測物數值(螢幕顯示L1)
完成量測後,連續按4兩下可直接計算獲得待測物之透光率(T)與吸收值(A)
---------------------------------------------------------------------
程式碼如下
//from -2-
//ok but btn slow
//-4- change btn
//from colormeter-tsl2561-oled-stm-4
//orange led 600-605nm,uv 365nm
#include <SoftWire.h>
//#define SDA PB11 //I2C 2//#define SCL PB10 //I2 2
#define SDA PB11//PB11 //PB7//I2C 1//
#define SCL PB10//PB10 //PB6 I2C 1
//SoftWire SWire(PB6, PB7, SOFT_FAST);
//SoftWire SWire(SCL, SDA, SOFT_STANDARD);//too slow affect btn
SoftWire SWire(SCL, SDA, SOFT_FAST);
#include "TSL2561_STM.h"
// the ADDR pin float (addr 0x39), or tie it to ground or vcc. In those cases
// use TSL2561_ADDR_LOW (0x29) or TSL2561_STM_ADDR_HIGH (0x49) respectively
//TSL2561 tsl(TSL2561_ADDR_FLOAT);
TSL2561_STM tsl(TSL2561_STM_ADDR_FLOAT);
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306Soft.h>
#define OLED_RESET 4
Adafruit_SSD1306Soft display(OLED_RESET);
#define SSD1306_WHITE WHITE
#define SCREEN_ADDRESS 0x3C
int rgbR = PA2;int rgbG = PA1;int rgbB = PA0;
int rgbRShow = PA5;int rgbGShow = PA4;int rgbBShow = PA3;
int beep = PC14;//11;
float pressLength_milliSeconds1 = 0;float pressLength_milliSeconds2 = 0;
float pressLength_milliSeconds3 = 0;float pressLength_milliSeconds4 = 0;
int short_milliSeconds1 = 4950;int short_milliSeconds2 = 4950;
int short_milliSeconds3 = 4950;int short_milliSeconds4 = 4950;
int long_milliSeconds1 = 5000; int long_milliSeconds2 = 5000;
int long_milliSeconds3 = 5000; int long_milliSeconds4 = 5000;
int btn1 = PB3;int btn2 = PA15;//uv led400 and ok led
int btn3 = PB5;int btn4 = PB4; //
int btn1Presses = 0;int btn2Presses = 0;
int btn3Presses = 0;int btn4Presses = 0;
uint16_t x;
float Lfirst; float Llast; float LAsorb;;float LT;
void baseScreenShow(){
display.clearDisplay();
display.setTextSize(1);display.setTextColor(SSD1306_WHITE);
display.setCursor(5, 0);display.println(F("Toppy!"));//display.display();
display.setTextSize(2);display.setTextColor(SSD1306_WHITE);
display.setCursor(46, 0);display.println(F("L:"));
display.setCursor(0, 16);display.println(F("L0:"));
display.setTextSize(2);display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 33);display.println(F("L1:"));
display.setTextSize(2);display.setTextColor(SSD1306_WHITE);
//display.setCursor(0, 50);display.println(F("A :"));
display.setCursor(62, 0);display.println(x);
if(btn4Presses == 1){
display.setCursor(0, 50);display.println(F("T :"));
}else{
display.setCursor(0, 50);display.println(F("A :"));
}
}
void runShow(){
display.setTextSize(2);display.setTextColor(SSD1306_WHITE);
//display.setCursor(10, 0);display.println(F("E:"));//display.display();
display.setTextSize(2);display.setTextColor(SSD1306_WHITE);
display.setCursor(36, 16);display.println(Lfirst);
display.setTextSize(2);display.setTextColor(SSD1306_WHITE);
display.setCursor(40, 33);display.println(Llast);
display.setTextSize(2);display.setTextColor(SSD1306_WHITE);
//display.setCursor(40, 50);display.println(LAsorb);
if(btn4Presses == 1){
display.setCursor(40, 50);display.println(LT);
}else{
display.setCursor(40, 50);display.println(LAsorb);
}
}
void beepS(){ //short
digitalWrite(beep, HIGH);delay(20);
digitalWrite(beep ,LOW);
}
void beepL(){ //long
digitalWrite(beep, HIGH);delay(100);
digitalWrite(beep ,LOW); delay(100);
digitalWrite(beep ,HIGH);delay(100);
digitalWrite(beep ,LOW); delay(100);
digitalWrite(beep ,HIGH);delay(100);
digitalWrite(beep ,LOW); delay(100);
digitalWrite(beep ,HIGH);delay(100);
digitalWrite(beep ,LOW); delay(50);
}
void RedRGB(){
digitalWrite(rgbR,HIGH);
digitalWrite(rgbG,LOW);
digitalWrite(rgbB,LOW);
digitalWrite(rgbRShow,HIGH);
digitalWrite(rgbGShow,LOW);
digitalWrite(rgbBShow,LOW);
}
void GreenRGB(){
digitalWrite(rgbR,LOW);
digitalWrite(rgbG,HIGH);
digitalWrite(rgbB,LOW);
digitalWrite(rgbRShow,LOW);
digitalWrite(rgbGShow,HIGH);
digitalWrite(rgbBShow,LOW);
}
void BlueRGB(){
digitalWrite(rgbR,LOW);
digitalWrite(rgbG,LOW);
digitalWrite(rgbB,HIGH);
digitalWrite(rgbRShow,LOW);
digitalWrite(rgbGShow,LOW);
digitalWrite(rgbBShow,HIGH);
}
void setup(void) {
pinMode(btn1, INPUT_PULLUP); pinMode(btn2, INPUT_PULLUP);
pinMode(btn3, INPUT_PULLUP); pinMode(btn4, INPUT_PULLUP);
pinMode(rgbR,OUTPUT); pinMode(rgbG,OUTPUT); pinMode(rgbB,OUTPUT);
pinMode(rgbRShow,OUTPUT); pinMode(rgbGShow,OUTPUT); pinMode(rgbBShow,OUTPUT);
pinMode(beep,OUTPUT);
Serial.begin(9600);
if (tsl.begin()) {
Serial.println("Found sensor");
} else {
Serial.println("No sensor?");
//while (1);
}
// You can change the gain on the fly, to adapt to brighter/dimmer light situations
//tsl.setGain(TSL2561_STM_GAIN_0X); // set no gain (for bright situtations)
tsl.setGain(TSL2561_STM_GAIN_16X); // set 16x gain (for dim situations)
// Changing the integration time gives you a longer time over which to sense light
// longer timelines are slower, but are good in very low light situtations!
//tsl.setTiming(TSL2561_STM_INTEGRATIONTIME_13MS); // shortest integration time (bright light)
//tsl.setTiming(TSL2561_INTEGRATIONTIME_101MS); // medium integration time (medium light)
tsl.setTiming(TSL2561_STM_INTEGRATIONTIME_402MS); // longest integration time (dim light)
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3D (for the 128x64)
display.clearDisplay();
baseScreenShow();
display.display();
RedRGB();
}
void loop(void) {
while (digitalRead(btn1) == LOW ){
delay(10);
pressLength_milliSeconds1 = pressLength_milliSeconds1 + 100;
//Serial.print("ms = "); //display how long button is has been held
//Serial.println(pressLength_milliSeconds);
}
if (pressLength_milliSeconds1 >= long_milliSeconds1){//long press
beepL();
digitalWrite(rgbR, LOW);
digitalWrite(rgbG, LOW);
digitalWrite(rgbB, LOW);
digitalWrite(rgbR, HIGH); //red
delay(200);
digitalWrite(rgbR, LOW);
delay(200);
digitalWrite(rgbR, HIGH); //red
delay(200);
digitalWrite(rgbR, LOW);
delay(200);
digitalWrite(rgbR, HIGH); //red
delay(200);
digitalWrite(rgbR, LOW);
delay(200);
} //option 1 - Execute the first option if the button is held for the correct amount of time
else if(pressLength_milliSeconds1 < short_milliSeconds1
&& pressLength_milliSeconds1 >= 100 ){
//digitalWrite(rgbG, HIGH); //green
//digitalWrite(rgbR, LOW);
beepS();
btn1Presses++;
switch(btn1Presses){
case 1:
GreenRGB();
break;
case 2:
BlueRGB();
break;
case 3:
RedRGB();
btn1Presses = 0;
break;
}
}
pressLength_milliSeconds1 = 0;
while (digitalRead(btn2) == LOW ){
delay(10);
pressLength_milliSeconds2 = pressLength_milliSeconds2 + 100;
}
if (pressLength_milliSeconds2 >= long_milliSeconds2){
beepL();
} //option 1 - Execute the first option if the button is held for the correct amount of time
else if(pressLength_milliSeconds2 < short_milliSeconds2
&& pressLength_milliSeconds2 >= 100 ){
beepS();
Lfirst = x;
}
pressLength_milliSeconds2 = 0;
while (digitalRead(btn3) == LOW ){
delay(10);
pressLength_milliSeconds3 = pressLength_milliSeconds3 + 100;
}
if (pressLength_milliSeconds3 >= long_milliSeconds3){
beepL();
} //option 1 - Execute the first option if the button is held for the correct amount of time
else if(pressLength_milliSeconds3 < short_milliSeconds3
&& pressLength_milliSeconds3 >= 100 ){
beepS();
Llast = x;
}
pressLength_milliSeconds3 = 0;
while (digitalRead(btn4) == LOW ){
delay(10);
pressLength_milliSeconds4 = pressLength_milliSeconds4 + 100;
}
if (pressLength_milliSeconds4 >= long_milliSeconds4){
beepL();
} //option 1 - Execute the first option if the button is held for the correct amount of time
else if(pressLength_milliSeconds4 < short_milliSeconds4
&& pressLength_milliSeconds4 >= 100 ){
beepS();
btn4Presses++;
switch(btn4Presses){
case 1://A
LAsorb = log10(((float)Lfirst) / Llast);
break;
case 2://T
LT = Llast/Lfirst *100;
btn4Presses = 0;
break;
}
}
pressLength_milliSeconds4 = 0;
/**/
//uint16_t x = tsl.getLuminosity(TSL2561_VISIBLE);
x = tsl.getLuminosity(TSL2561_STM_FULLSPECTRUM);
//uint16_t x = tsl.getLuminosity(TSL2561_INFRARED);
//Serial.println(x, DEC);
/*
// More advanced data read example. Read 32 bits with top 16 bits IR, bottom 16 bits full spectrum
uint32_t lum = tsl.getFullLuminosity();
uint16_t ir, full;
ir = lum >> 16;
full = lum & 0xFFFF;
Serial.print("IR: "); Serial.print(ir); Serial.print("\t\t");
Serial.print("Full: "); Serial.print(full); Serial.print("\t");
Serial.print("Visible: "); Serial.print(full - ir); Serial.print("\t");
Serial.print("Lux: "); Serial.println(tsl.calculateLux(full, ir));
*/
baseScreenShow();
runShow();
display.display();
delay(2);
}
沒有留言:
張貼留言