/
trans_v2.c
76 lines (69 loc) · 1.19 KB
/
trans_v2.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <wiringPi.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
int main()
{
FILE *fp;
fp= fopen ("logfile.txt","w+");
char inp[5]= "UUUUU";
short i=0;
//short length=strlen(inp);
short length=5;
fprintf(fp,"%d ",length);
short j=0,k=0;
short ascii_out[length];
short bit_out[8*length];
short n_zero=0;
//short repeat=3;
while(j<length){
ascii_out[j] = (int) inp[j];
fprintf(fp," ascii %d bits ",ascii_out[j]);
if(ascii_out[j]<2)
n_zero=7;
else if(ascii_out[j]<4)
n_zero=6;
else if(ascii_out[j]<8)
n_zero=5;
else if(ascii_out[j]<16)
n_zero=4;
else if(ascii_out[j]<32)
n_zero=3;
else if(ascii_out[j]<64)
n_zero=2;
else if(ascii_out[j]<128)
n_zero=1;
for(k=0;k<n_zero;k++){
bit_out[8*j+i]=0;
fprintf(fp,"%d ",bit_out[8*j+i]);
i++;
}
while(ascii_out[j]>0){
bit_out[8*j+i]=ascii_out[j]%2;
ascii_out[j]=ascii_out[j]/2;
fprintf(fp,"%d ",bit_out[8*j+i]);
i++;
}
i=0;
j++;
}
fclose(fp);
if(wiringPiSetup() == -1)
exit(1);
pinMode(7,OUTPUT);
while(1){
j=0;//k=0;
while(j<8*length){
//while(k<repeat){
if(bit_out[j]==1)
digitalWrite(7,1);
else if(bit_out[j]==0)
digitalWrite(7,0);
//k++;
//}
j++;
}
}
return 0;
}