Difference between revisions of "Persistence of Vision and Temperature sensor Arduino code"
From Hackteria Wiki
(9 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
+ | [[File:circuitdiagram_POV_temp.png|600px]] | ||
+ | |||
+ | <pre> | ||
//Reading realtime values of a sensor using persistence of vision typography using the Arduino | //Reading realtime values of a sensor using persistence of vision typography using the Arduino | ||
Line 18: | Line 21: | ||
int C[] = {1,1,1,1,1, 1,0,0,0,1, 1,0,0,0,1}; | int C[] = {1,1,1,1,1, 1,0,0,0,1, 1,0,0,0,1}; | ||
int minus[] = {0,0,1,0,0, 0,0,1,0,0, 0,0,1,0,0}; | int minus[] = {0,0,1,0,0, 0,0,1,0,0, 0,0,1,0,0}; | ||
+ | |||
int letterSpace; | int letterSpace; | ||
int dotTime; | int dotTime; | ||
int temp; | int temp; | ||
− | |||
int tempPin = 0; | int tempPin = 0; | ||
void setup() | void setup() | ||
− | { | + | { |
Serial.begin(9600); | Serial.begin(9600); | ||
+ | |||
// setting the ports of the leds to OUTPUT | // setting the ports of the leds to OUTPUT | ||
pinMode(2, OUTPUT); | pinMode(2, OUTPUT); | ||
Line 34: | Line 38: | ||
pinMode(5, OUTPUT); | pinMode(5, OUTPUT); | ||
pinMode(6, OUTPUT); | pinMode(6, OUTPUT); | ||
+ | |||
// defining the space between the letters (ms) | // defining the space between the letters (ms) | ||
letterSpace = 6; | letterSpace = 6; | ||
// defining the time dots appear (ms) | // defining the time dots appear (ms) | ||
dotTime = 3; | dotTime = 3; | ||
− | }void printLetter(int letter[]) | + | } |
+ | |||
+ | void printLetter(int letter[]) | ||
{ | { | ||
int y; | int y; | ||
Line 69: | Line 76: | ||
} | } | ||
delay(letterSpace); | delay(letterSpace); | ||
− | } | + | } |
+ | |||
void loop() | void loop() | ||
{ | { | ||
− | |||
int ara[2]; //Array to store separate digits of the temperature value. | int ara[2]; //Array to store separate digits of the temperature value. | ||
int count=0; | int count=0; | ||
Line 87: | Line 94: | ||
// To calculate the number of digits in the temperature sensor value | // To calculate the number of digits in the temperature sensor value | ||
− | + | if (temp > 0) | |
− | |||
{ | { | ||
while(n!=0) | while(n!=0) | ||
Line 131: | Line 137: | ||
printLetter(C); | printLetter(C); | ||
} | } | ||
+ | |||
+ | </pre> |
Latest revision as of 16:13, 12 April 2015
//Reading realtime values of a sensor using persistence of vision typography using the Arduino // array for displaying numbers or letters int _[] = {0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0}; int num1[] = {0,1,0,0,1, 1,1,1,1,1, 0,0,0,0,1}; int num2[] = {1,0,1,1,1, 1,0,1,0,1, 1,1,1,0,1}; int num3[] = {0,1,0,1,0, 1,0,1,0,1, 1,1,1,1,1}; int num4[] = {1,1,1,0,0, 0,0,1,0,0, 1,1,1,1,1}; int num5[] = {1,1,1,0,1, 1,0,1,0,1, 1,0,1,1,1}; int num6[] = {1,1,1,1,1, 1,0,1,0,1, 1,0,1,1,1}; int num7[] = {1,0,0,0,0, 1,0,0,0,0, 1,1,1,1,1}; int num8[] = {1,1,1,1,1, 1,0,1,0,1, 1,1,1,1,1}; int num9[] = {1,1,1,0,1, 1,0,1,0,1, 1,1,1,1,1}; int num0[] = {1,1,1,1,1, 1,0,0,0,1, 1,1,1,1,1}; int dot[] = {0,0,0,0,0, 1,1,0,0,0, 1,1,0,0,0}; int C[] = {1,1,1,1,1, 1,0,0,0,1, 1,0,0,0,1}; int minus[] = {0,0,1,0,0, 0,0,1,0,0, 0,0,1,0,0}; int letterSpace; int dotTime; int temp; int tempPin = 0; void setup() { Serial.begin(9600); // setting the ports of the leds to OUTPUT pinMode(2, OUTPUT); pinMode(3, OUTPUT); pinMode(4, OUTPUT); pinMode(5, OUTPUT); pinMode(6, OUTPUT); // defining the space between the letters (ms) letterSpace = 6; // defining the time dots appear (ms) dotTime = 3; } void printLetter(int letter[]) { int y; // printing the first y row of the letter for (y=0; y<5; y++) { digitalWrite(y+2, letter[y]); } delay(dotTime); // printing the second y row of the letter for (y=0; y<5; y++) { digitalWrite(y+2, letter[y+5]); } delay(dotTime); // printing the third y row of the letter for (y=0; y<5; y++) { digitalWrite(y+2, letter[y+10]); } delay(dotTime); // printing the sspace between the letters for (y=0; y<5; y++) { digitalWrite(y+2, 0); } delay(letterSpace); } void loop() { int ara[2]; //Array to store separate digits of the temperature value. int count=0; int n; //To calculate values from the LM35 temp = analogRead(tempPin); temp = temp * 0.48828125; //Serial.print(temp); if (temp == 0) printLetter(num0); n=temp; //make a copy of the temperature value in another variable. // To calculate the number of digits in the temperature sensor value if (temp > 0) { while(n!=0) { n=n/10; ++count; } } //to store the digits of the temperature value in an array for(int i=0;i<=count;i++) { ara[i]=temp%10; temp=temp/10; } //loop to output the digits stored in the array for(int i=count;i>=0;i--) { if (ara[i] == 1) printLetter(num1); if (ara[i] == 2) printLetter(num2); if (ara[i] == 3) printLetter(num3); if (ara[i] == 4) printLetter(num4); if (ara[i] == 5) printLetter(num5); if (ara[i] == 6) printLetter(num6); if (ara[i] == 7) printLetter(num7); if (ara[i] == 8) printLetter(num8); if (ara[i] == 9) printLetter(num9); if (ara[i] == 0) printLetter(num0); } delay(5); printLetter(dot); printLetter(C); }