// https://robojax.com/learn/arduino/?vid=robojax_TEMT6000_phototransistor
/*
* This is Arduino Sketch for TEMT6000 Phototransistor Module
* This code reads the voltage of common Collector configuration
* and displays the voltage in Volts.
* V pin is connected to 5V
* G pin is connected to ground GND
* S pin is signal connected to A0 of Arduino
*
Written by Ahmad Shamshiri for Robojax.com
* on May 10, 2018 at 14:14 at Ajax, Ontario, Canada
* This code is provided at http://robojax.com
* Watch Video instruction for this code:https://youtu.be/pxR6e-3XkIk
*/
#define light A0 // define input pin
#include <TM1637Display.h>
//https://deepbluembedded.com/seven-segment-display-generator/
const uint8_t SEG_Over[] = {
SEG_A | SEG_D | SEG_E | SEG_F, // [
};
const uint8_t SEG_OFF[] = {0, 0, 0, 0};
const uint8_t AllOn[] = {0xff, 0xff, 0xff, 0xff};
// In this library, the byte order is .GFEDCBA
// GLOBALS
// Create a display object, specifying parameters (Clock pin, Data pin)
TM1637Display display(4, 5);
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
display.setBrightness(5);
display.setSegments(AllOn);
delay(800);
display.setSegments(SEG_OFF);
}
void MyDisplay(float i) {
display.showNumberDec(i, false, 4, 0);
}
void loop() {
// TEMT6000 Roboajx.com code
int Lvalue = analogRead(light);// read the light
int mVolt = map(Lvalue,0, 1023, 0, 5000);// map analogue reading to 5000mV
float volt =(double)mVolt/1000;// convert millivolt to volt
Serial.print(mVolt);// print millivolt
Serial.print( "mV ");
Serial.print(volt,3);// print volts with 3 decimal places
Serial.println( "V ");
delay(500);// wait for 1000 milliseconds
// TEMT6000 Roboajx.com code
MyDisplay(Lvalue);
}