Difference between revisions of "Persistence of Vision and Temperature sensor Arduino code"
Line 1: | Line 1: | ||
− | //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<br> |
− | // array for displaying numbers or letters | + | // array for displaying numbers or letters<br> |
− | int _[] = {0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0}; | + | int _[] = {0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0};<br> |
− | int num1[] = {0,1,0,0,1, 1,1,1,1,1, 0,0,0,0,1}; | + | int num1[] = {0,1,0,0,1, 1,1,1,1,1, 0,0,0,0,1};<br> |
− | int num2[] = {1,0,1,1,1, 1,0,1,0,1, 1,1,1,0,1}; | + | int num2[] = {1,0,1,1,1, 1,0,1,0,1, 1,1,1,0,1};<br> |
− | int num3[] = {0,1,0,1,0, 1,0,1,0,1, 1,1,1,1,1}; | + | int num3[] = {0,1,0,1,0, 1,0,1,0,1, 1,1,1,1,1};<br> |
− | int num4[] = {1,1,1,0,0, 0,0,1,0,0, 1,1,1,1,1}; | + | int num4[] = {1,1,1,0,0, 0,0,1,0,0, 1,1,1,1,1};<br> |
− | int num5[] = {1,1,1,0,1, 1,0,1,0,1, 1,0,1,1,1}; | + | int num5[] = {1,1,1,0,1, 1,0,1,0,1, 1,0,1,1,1};<br> |
− | int num6[] = {1,1,1,1,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};<br> |
− | int num7[] = {1,0,0,0,0, 1,0,0,0,0, 1,1,1,1,1}; | + | int num7[] = {1,0,0,0,0, 1,0,0,0,0, 1,1,1,1,1};<br> |
− | int num8[] = {1,1,1,1,1, 1,0,1,0,1, 1,1,1,1,1}; | + | int num8[] = {1,1,1,1,1, 1,0,1,0,1, 1,1,1,1,1};<br> |
− | int num9[] = {1,1,1,0,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};<br> |
− | int num0[] = {1,1,1,1,1, 1,0,0,0,1, 1,1,1,1,1}; | + | int num0[] = {1,1,1,1,1, 1,0,0,0,1, 1,1,1,1,1};<br> |
− | int dot[] = {0,0,0,0,0, 1,1,0,0,0, 1,1,0,0,0}; | + | int dot[] = {0,0,0,0,0, 1,1,0,0,0, 1,1,0,0,0};<br> |
− | 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};<br> |
− | 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};<br> |
− | int letterSpace; | + | int letterSpace;<br> |
− | int dotTime; | + | int dotTime;<br> |
− | int temp; | + | int temp;<br> |
− | int tempPin = 0; | + | int tempPin = 0;<br> |
void setup() | void setup() | ||
Line 38: | Line 38: | ||
// 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 70: | Line 72: | ||
delay(letterSpace); | delay(letterSpace); | ||
} | } | ||
+ | |||
void loop() | void loop() | ||
{ | { |
Revision as of 12:41, 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);
}