RGB型分光光度計 組裝
最簡單、最容易組裝的儀器就在這了!一起動手做吧!
所需材料:
蜂鳴器:5V蜂鳴器
電路板:Arduino Uno R3 開發板
偵測器:型號 TSL-2561 傳感器
聚光透鏡:LED玻璃聚光鏡
光源:Arduino 3色LED-RGB模組 KY-016
光源選擇指示燈:3色LED模組-RGB
數值顯示器:0.96寸 藍色IIC通信小OLED顯示屏模塊
下層
上層
---------------------------------------------------------------------操作
1.首先插上電源即開機,按1選擇所需光源(紅R-650 nm、綠-G550nm、藍B-450nm)
2.將Cuvette置於樣品放置處,即開始量測。
第一行之L值為未換算前的穿透係數。
按下2可記錄空白組數值(螢幕顯示L0),按3可記錄待測物數值(螢幕顯示L1)
完成量測後,連續按4兩下可直接計算獲得待測物之透光率(T)與吸收值(A)
---------------------------------------------------------------------
程式碼如下
//from -2-
#include "TSL2561.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);
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
int rgbR = 5;int rgbG = 6;int rgbB = 7;
int rgbRShow = 8;int rgbGShow = 9;int rgbBShow = 10;
int beep = 11;
#include <Button.h>
Button btn1 = Button(A0, LOW);
Button btn2 = Button(A1, LOW);
Button btn3 = Button(A2, LOW);
Button btn4 = Button(A3, LOW);
uint16_t x;
float Lfirst; float Llast; float LAsorb;;float LT;
int btn1Presses = 0;
int btn4Presses = 0;
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(50, 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(70, 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(40, 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(50);
digitalWrite(beep ,LOW);delay(55);
digitalWrite(beep ,HIGH);delay(55);
digitalWrite(beep ,LOW);
}
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(rgbR,OUTPUT); pinMode(rgbG,OUTPUT); pinMode(rgbB,OUTPUT);
pinMode(rgbRShow,OUTPUT); pinMode(rgbGShow,OUTPUT); pinMode(rgbBShow,OUTPUT);
pinMode(beep,OUTPUT);
BlueRGB();
Serial.begin(9600);
if (tsl.begin()) {
Serial.println("Found sensor");
} else {
Serial.println("No tsl2561");
while (1);
}
// You can change the gain on the fly, to adapt to brighter/dimmer light situations
tsl.setGain(TSL2561_GAIN_0X); // set no gain (for bright situtations)
//tsl.setGain(TSL2561_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_INTEGRATIONTIME_13MS); // shortest integration time (bright light)
//tsl.setTiming(TSL2561_INTEGRATIONTIME_101MS); // medium integration time (medium light)
//tsl.setTiming(TSL2561_INTEGRATIONTIME_402MS); // longest integration time (dim light)
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
//display.invertDisplay(true);
display.clearDisplay();
baseScreenShow();
display.display();
}
void loop(void) {
btn1.listen();
if(btn1.onRelease()){
beepS();
btn1Presses++;
switch(btn1Presses){
case 1:
GreenRGB();
break;
case 2:
BlueRGB();
break;
case 3:
RedRGB();
btn1Presses = 0;
break;
}
}
btn2.listen();
if (btn2.onRelease()){
beepS();
Lfirst = x;
}
btn3.listen();
if (btn3.onRelease()){
beepS();
Llast = x;
}
btn4.listen();
if (btn4.onRelease()){
beepS();
btn4Presses++;
switch(btn4Presses){
case 1://A
LAsorb = log10(((float)Lfirst) / Llast);
break;
case 2://T
LT = Llast/Lfirst *100;
btn4Presses = 0;
break;
}
}
/**/
//uint16_t x = tsl.getLuminosity(TSL2561_VISIBLE);
x = tsl.getLuminosity(TSL2561_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(100);
}
沒有留言:
張貼留言