EasyManua.ls Logo

SeeedStudio Grove Series - Page 30

Default Icon
51 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Created by Oliver Wang
This example code is in the public domain.
http://www.seeedstudio.com/wiki/GROVE_-_Starter_Kit_v1.1b#Grove_-
_Rotary_Angle_Sensor
*/
#include "TM1637.h"
/* Macro Define */
#define CLK 39 /* 4-digital display clock pin */
#define DIO 38 /* 4-digital display data pin */
#define ROTARY_ANGLE_P 24 /* pin of rotary angle sensor */
/* Global Variables */
TM1637 tm1637(CLK, DIO); /* 4-digital display object */
int analog_value = 0; /* variable 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(ROTARY_ANGLE_P); /* 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 */
}
delay(100);
}
RESULT
A digital number corresponding to the analog reading coming from the potentiometer knob will
display on the 4-Digit Display module. Note that depending on the resolution of your LaunchPad

Related product manuals