EasyManuals Logo

SeeedStudio Grove Series User Manual

Default Icon
51 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #33 background imageLoading...
Page #33 background image
Created by Oliver Wang
This example code is in the public domain.
http://www.seeedstudio.com/depot/Grove-Light-Sensor-p-746.html?cPath=25_27
*/
#include "TM1637.h"
/* Macro Define */
#define CLK 39 /* 4-digital display clock pin */
#define DIO 38 /* 4-digiral display data pin */
#define LIGHT_SENSOR 24 /* pin of grove light sensor */
/* Global Varibles */
TM1637 tm1637(CLK, DIO); /* 4-digital display object */
int analog_value = 0; /* varible to store the value coming from rotary angle sensor
*/
int8_t bits[4] = {0}; /* array to store the single bits of the value */
/* the setup() method runs once, when the sketch starts */
void setup() {
/* Initialize 4-digital display */
tm1637.init();
tm1637.set(BRIGHT_TYPICAL);
}
/* the loop() method runs over and over again */
void loop() {
analog_value = analogRead(LIGHT_SENSOR); /* read the value from the sensor */
memset(bits, 0, 4); /* reset array when we use it */
for(int i = 3; i >= 0; i--) {
/* get single bits of the analog value */
bits[i] = analog_value % 10;
analog_value = analog_value / 10;
tm1637.display(i, bits[i]); /* display by 4-digital display */
}
}
RESULT
The value will be displayed on 4-Digit Display when you shine a light on the light sensor. Note
that depending on the resolution of your LaunchPad kit’s ADC (analog-to-digital converter), your
range may vary. For an 8-bit ADC, a number from 0-255 will show. For a 10-bit ADC, a number

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the SeeedStudio Grove Series and is the answer not in the manual?

SeeedStudio Grove Series Specifications

General IconGeneral
BrandSeeedStudio
ModelGrove Series
CategoryMicrocontrollers
LanguageEnglish

Related product manuals