Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Update chapter-3/4Char

  • Loading branch information...
commit 56da40946d216a3650777fb5f4b8b04961feb787 1 parent 6058746
Emily Gertz authored

Showing 1 changed file with 113 additions and 118 deletions. Show diff stats Hide diff stats

  1. +113 118 chapter-3/4Char
231 chapter-3/4Char
@@ -7,138 +7,133 @@
7 7 */
8 8
9 9 #include <SoftwareSerial.h>
  10 +
10 11 #define SerialIn 2
11 12 #define SerialOut 3
12   -#define 4Delay 600
13 13
  14 +#define Xdelay 600
14 15
15   -SoftwareSerial mySerialPort(SerialIn, SerialOut);
  16 +String txtmessage = "HELLo ThErE";
  17 +
  18 +byte thou=0;
  19 +byte hund=0;
  20 +byte tens=0;
  21 +byte ones=0;
16 22
17 23
  24 +SoftwareSerial mySerialPort(SerialIn, SerialOut);
  25 +
18 26 void setup()
19 27 {
20   -pinMode(SerialOut, OUTPUT);
21   -pinMode(SerialIn, INPUT);
  28 + pinMode(SerialOut, OUTPUT);
  29 + pinMode(SerialIn, INPUT);
22 30
23   -//Set the port speed
24   -mySerialPort.begin(9600);
25 31
26   -//Send the character 'v' to reset the display
27   -mySerialPort.print("v");
  32 + // open communications with the 4char display
  33 + mySerialPort.begin(9600);
28 34
29   -}
  35 + // the 'v' character resets the display
  36 + mySerialPort.print("v");
30 37
  38 +}
31 39
32 40 void loop()
33 41 {
  42 + thou=0;
  43 + hund=0;
  44 + tens=0;
  45 + ones=0;
  46 +
  47 +
  48 + // light up all segments as a test
  49 + mySerialPort.print("----");
  50 + delay(Xdelay);
  51 + mySerialPort.print("8888");
  52 + delay(Xdelay);
  53 + mySerialPort.print("----");
  54 + delay(Xdelay);
  55 + mySerialPort.print("xxxx");
  56 + delay(Xdelay);
  57 +
  58 +
  59 +
  60 + // scroll from 1 to 0 the hard way
  61 + mySerialPort.print("xxxx");
  62 + delay(Xdelay);
  63 + mySerialPort.print("xxx1");
  64 + delay(Xdelay);
  65 + mySerialPort.print("xx12");
  66 + delay(Xdelay);
  67 + mySerialPort.print("x123");
  68 + delay(Xdelay);
  69 + mySerialPort.print("1234");
  70 + delay(Xdelay);
  71 + mySerialPort.print("2345");
  72 + delay(Xdelay);
  73 + mySerialPort.print("3456");
  74 + delay(Xdelay);
  75 + mySerialPort.print("4567");
  76 + delay(Xdelay);
  77 + mySerialPort.print("5678");
  78 + delay(Xdelay);
  79 + mySerialPort.print("6789");
  80 + delay(Xdelay);
  81 + mySerialPort.print("7890");
  82 + delay(Xdelay);
  83 + mySerialPort.print("8900");
  84 + delay(Xdelay);
  85 + mySerialPort.print("9000");
  86 + delay(Xdelay);
  87 + mySerialPort.print("0000");
  88 + delay(Xdelay);
  89 +
  90 +
  91 + // Count from 0 to 1008 by nines
  92 +
  93 + for (int i =0; i <=1008; i=i+9)
  94 + {
  95 + ones = i%10;
  96 + if(i>=10) tens = ((i%100)-ones)/10;
  97 + if(i>=100) hund = ((i%1000)-(tens*10)-ones)/100;
  98 + if(i>=1000) thou = ((i%10000)-(hund*100)-(tens*10)-ones)/1000;
  99 +
  100 + mySerialPort.print(thou);
  101 + mySerialPort.print(hund);
  102 + mySerialPort.print(tens);
  103 + mySerialPort.print(ones);
  104 +
  105 + delay(Xdelay/10);
  106 + }
  107 +
  108 +
  109 +
  110 + delay(Xdelay);
  111 + mySerialPort.print("xxxx");
  112 + delay(Xdelay);
  113 +
  114 +
  115 + // Scroll a txtmessage a more complicated way
  116 + // First add the appropriate buffer
  117 + txtmessage = "xxxx"+txtmessage+"xxxxx";
  118 + // then convert from String object to char array,
  119 + // which is the only thing SoftwareSerial can print
  120 + char temps[txtmessage.length()];
  121 + txtmessage.toCharArray(temps,txtmessage.length());
  122 +
  123 + // then scroll through the txtmessage
  124 + for(int i = 0; i <= txtmessage.length()-5; i++)
  125 + {
  126 + mySerialPort.print(temps[i]);
  127 + mySerialPort.print(temps[i+1]);
  128 + mySerialPort.print(temps[i+2]);
  129 + mySerialPort.print(temps[i+3]);
  130 + delay(Xdelay);
  131 + }
  132 +
  133 +
  134 + delay(Xdelay);
  135 + delay(Xdelay);
  136 + delay(Xdelay);
34 137
  138 +}
35 139
36   -// The 4Char treats the character 'x' as a blank space.
37   -mySerialPort.print("xxxx");
38   -delay(4Delay);
39   -
40   -mySerialPort.print("xxx1");
41   -delay(4Delay);
42   -
43   -mySerialPort.print("xx12");
44   -delay(4Delay);
45   -
46   -mySerialPort.print("x123");
47   -delay(4Delay);
48   -
49   -mySerialPort.print("1234");
50   -delay(4Delay);
51   -
52   -mySerialPort.print("2345");
53   -delay(4Delay);
54   -
55   -mySerialPort.print("3456");
56   -delay(4Delay);
57   -
58   -mySerialPort.print("4567");
59   -delay(4Delay);
60   -
61   -mySerialPort.print("5678");
62   -delay(4Delay);
63   -
64   -mySerialPort.print("6789");
65   -delay(4Delay);
66   -
67   -mySerialPort.print("7890");
68   -delay(4Delay);
69   -
70   -mySerialPort.print("8900");
71   -delay(4Delay);
72   -
73   -mySerialPort.print("9000");
74   -delay(4Delay);
75   -
76   -mySerialPort.print("0000");
77   -delay(4Delay);
78   -
79   -
80   -
81   -mySerialPort.print("----");
82   -delay(4Delay);
83   -
84   -mySerialPort.print("8888");
85   -delay(4Delay);
86   -
87   -mySerialPort.print("----");
88   -delay(4Delay);
89   -
90   -mySerialPort.print("xxxx");
91   -delay(4Delay);
92   -
93   -
94   -
95   -mySerialPort.print("xxxH");
96   -delay(4Delay);
97   -
98   -mySerialPort.print("xxHE");
99   -delay(4Delay);
100   -
101   -mySerialPort.print("xHEL");
102   -delay(4Delay);
103   -
104   -mySerialPort.print("HELL");
105   -delay(4Delay);
106   -
107   -mySerialPort.print("ELLO");
108   -delay(4Delay);
109   -
110   -mySerialPort.print("LLOx");
111   -delay(4Delay);
112   -
113   -mySerialPort.print("LOxt");
114   -delay(4Delay);
115   -
116   -mySerialPort.print("Lxth");
117   -delay(4Delay);
118   -
119   -mySerialPort.print("xthE");
120   -delay(4Delay);
121   -
122   -mySerialPort.print("thEr");
123   -delay(4Delay);
124   -
125   -mySerialPort.print("hErE");
126   -delay(4Delay);
127   -
128   -mySerialPort.print("ErEx");
129   -delay(4Delay);
130   -
131   -mySerialPort.print("rExx");
132   -delay(4Delay);
133   -
134   -mySerialPort.print("Exxx");
135   -delay(4Delay);
136   -
137   -mySerialPort.print("xxxx");
138   -delay(4Delay);
139   -delay(4Delay);
140   -delay(4Delay);
141   -delay(4Delay);
142   -
143   -
144   -}

0 comments on commit 56da409

Please sign in to comment.
Something went wrong with that request. Please try again.