Browse code

first commit

brice authored on 10/12/2014 12:41:39
Showing 2 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,105 @@
0
+binary hero by phil
1
+  
2
+  
3
+  Hardware part
4
+  
5
+  +5V--------------------------------------------------
6
+     |      |      |      |      |      |      |      |  
7
+     |      |      |      |      |      |      |      |     
8
+     +-/    + /    + /    + /    + /    + /    + /    + /   
9
+      /      /      /      /      /      /      /      /      
10
+     /      /      /      /      /      /      /      /      
11
+     |      |      |      |      |      |      |      |      
12
+     +-D2   +-D3   +-D4   +-D5   +-D6   +-D7   +-D10  +-D11   
13
+     |      |      |      |      |      |      |      |      
14
+     -      -      -      -      -      -      -      -      
15
+    |R|    |R|    |R|    |R|    |R|    |R|    |R|    |R|   
16
+    |1|    |1|    |1|    |1|    |1|    |1|    |1|    |1|   
17
+     -      -      -      -      -      -      -      -     
18
+     |      |      |      |      |      |      |      |      
19
+     |      |      |      |      |      |      |      |      
20
+  GND--------------------------------------------------
21
+  
22
+  
23
+  
24
+  
25
+  
26
+  +5V------------------------------------
27
+     |      |      |      |      |      |  
28
+     |      |      |      |      |      |     
29
+     +-/    +-/    + /    + /    + /    + /   
30
+   [--/      /      /      /      /      /       
31
+     /      /      /      /      /      /        
32
+     |      |      |      |      |      |        
33
+     +-D12  +-D13  +-A0   +-A1   +-A2   +-A3   
34
+     |      |      |      |      |      |         
35
+     -      -      -      -      -      -         
36
+    |R|    |R|    |R|    |R|    |R|    |R|     
37
+    |1|    |1|    |1|    |1|    |1|    |1|    
38
+     -      -      -      -      -      -        
39
+     |      |      |      |      |      |         
40
+     |      |      |      |      |      |         
41
+  GND------------------------------------
42
+  
43
+  
44
+      
45
+  D8-|    D8-|
46
+     |       |
47
+     _       _
48
+    \ /     \ /
49
+     -       -
50
+     |       | 
51
+     -       -  
52
+    |R|     |R|      
53
+    |2|     |3|     
54
+     -       - 
55
+     |       |
56
+     |       |
57
+     ---------
58
+         |
59
+         |----
60
+         |   |
61
+         |   -
62
+         |  |R|
63
+         |  |4|
64
+         |   -
65
+         |   |
66
+         |   |----->To Gnd
67
+        To   To
68
+        RCA  RCA
69
+        Pin  GND   
70
+  
71
+  ________________________________
72
+  Pin|    Role      |Information |
73
+  ________________________________
74
+  D2 |Bit 2^0       |NC switch   |
75
+  D3 |Bit 2^1       |NO switch   |        
76
+  D4 |Bit 2^2       |NO switch   |     
77
+  D5 |Bit 2^3       |NO switch   |   
78
+  D6 |Bit 2^4       |NO switch   |   
79
+  D7 |Bit 2^5       |NO switch   |    
80
+  D8 |Tvout Video   |            |
81
+  D9 |Tvout Sync    |            |
82
+  D10|Bit 2^6       |NO switch   |
83
+  D11|Bit 2^7       |NO switch   |
84
+  D12|Help button   |NC switch   |
85
+  D13|Pap button    |NC button   |
86
+  A0 |nb bits select|NO switch   |
87
+  A1 |nb bits select|NO switch   |
88
+  A2 |speed select  |NO switch   |
89
+  A3 |speed select  |NO switch   |
90
+  ________________________________
91
+  
92
+  
93
+  NO = Normaly open
94
+  NC = Normaly close
95
+  
96
+  
97
+  R1 = 10 Kohms
98
+  R2 = 330 ohms
99
+  R3 = 1 Kohms
100
+  R4 = 75 ohms
101
+  For leds I use basic red leds (I suppose you can use basic signal diode, but I haven't make the test...)
102
+ 
103
+You need TVout lib on http://code.google.com/p/arduino-tvout/downloads/list
104
+  
0 105
new file mode 100644
... ...
@@ -0,0 +1,403 @@
0
+  /*
1
+  
2
+  binary hero
3
+  
4
+  
5
+  
6
+  
7
+  Hardware part
8
+  
9
+  +5V--------------------------------------------------
10
+     |      |      |      |      |      |      |      |  
11
+     |      |      |      |      |      |      |      |     
12
+     +-/    + /    + /    + /    + /    + /    + /    + /   
13
+      /      /      /      /      /      /      /      /      
14
+     /      /      /      /      /      /      /      /      
15
+     |      |      |      |      |      |      |      |      
16
+     +-D2   +-D3   +-D4   +-D5   +-D6   +-D7   +-D10  +-D11   
17
+     |      |      |      |      |      |      |      |      
18
+     -      -      -      -      -      -      -      -      
19
+    |R|    |R|    |R|    |R|    |R|    |R|    |R|    |R|   
20
+    |1|    |1|    |1|    |1|    |1|    |1|    |1|    |1|   
21
+     -      -      -      -      -      -      -      -     
22
+     |      |      |      |      |      |      |      |      
23
+     |      |      |      |      |      |      |      |      
24
+  GND--------------------------------------------------
25
+  
26
+  
27
+  
28
+  
29
+  
30
+  +5V------------------------------------
31
+     |      |      |      |      |      |  
32
+     |      |      |      |      |      |     
33
+     +-/    +-/    + /    + /    + /    + /   
34
+   [--/      /      /      /      /      /       
35
+     /      /      /      /      /      /        
36
+     |      |      |      |      |      |        
37
+     +-D12  +-D13  +-A0   +-A1   +-A2   +-A3   
38
+     |      |      |      |      |      |         
39
+     -      -      -      -      -      -         
40
+    |R|    |R|    |R|    |R|    |R|    |R|     
41
+    |1|    |1|    |1|    |1|    |1|    |1|    
42
+     -      -      -      -      -      -        
43
+     |      |      |      |      |      |         
44
+     |      |      |      |      |      |         
45
+  GND------------------------------------
46
+  
47
+  
48
+      
49
+  D8-|    D8-|
50
+     |       |
51
+     _       _
52
+    \ /     \ /
53
+     -       -
54
+     |       | 
55
+     -       -  
56
+    |R|     |R|      
57
+    |2|     |3|     
58
+     -       - 
59
+     |       |
60
+     |       |
61
+     ---------
62
+         |
63
+         |----
64
+         |   |
65
+         |   -
66
+         |  |R|
67
+         |  |4|
68
+         |   -
69
+         |   |
70
+         |   |----->To Gnd
71
+        To   To
72
+        RCA  RCA
73
+        Pin  GND   
74
+  
75
+  ________________________________
76
+  Pin|    Role      |Information |
77
+  ________________________________
78
+  D2 |Bit 2^0       |NC switch   |
79
+  D3 |Bit 2^1       |NO switch   |        
80
+  D4 |Bit 2^2       |NO switch   |     
81
+  D5 |Bit 2^3       |NO switch   |   
82
+  D6 |Bit 2^4       |NO switch   |   
83
+  D7 |Bit 2^5       |NO switch   |    
84
+  D8 |Tvout Video   |            |
85
+  D9 |Tvout Sync    |            |
86
+  D10|Bit 2^6       |NO switch   |
87
+  D11|Bit 2^7       |NO switch   |
88
+  D12|Help button   |NC switch   |
89
+  D13|Pap button    |NC button   |
90
+  A0 |nb bits select|NO switch   |
91
+  A1 |nb bits select|NO switch   |
92
+  A2 |speed select  |NO switch   |
93
+  A3 |speed select  |NO switch   |
94
+  ________________________________
95
+  
96
+  
97
+  NO = Normaly open
98
+  NC = Normaly close
99
+  
100
+  
101
+  R1 = 10 Kohms
102
+  R2 = 330 ohms
103
+  R3 = 1 Kohms
104
+  R4 = 75 ohms
105
+  For leds I use basic red leds (I suppose you can use basic signal diode, but I haven't make the test...)
106
+  */
107
+  
108
+  
109
+  #include <TVout.h>
110
+  // You can found this lib on http://code.google.com/p/arduino-tvout/downloads/list
111
+  // I use this one : TVout_w_audio.zip 	R5.91 with added sound output on port B pin 3 (digital pin 11 m168/328 only for now) by adam wolf 
112
+  
113
+  #include <stdlib.h> //for itoa function
114
+  
115
+  //button setup
116
+  #define b1 2
117
+  #define b2 3
118
+  #define b4 4
119
+  #define b8 5
120
+  #define b16 6
121
+  #define b32 7
122
+  #define b64 10
123
+  #define b128 11
124
+  
125
+  #define bhelp 12
126
+  
127
+  #define bbutton 13
128
+  
129
+  #define bbit1 14
130
+  #define bbit2 15
131
+  
132
+  #define bspeed1 16
133
+  #define bspeed2 17
134
+  
135
+  
136
+  
137
+  TVout TV;
138
+  //bonus variables
139
+  int x = 0;
140
+  char xx[10]; 
141
+  //help string
142
+  char charhelp[10]; 
143
+  //score string
144
+  char charscore[10];
145
+  //number string
146
+  char charnum[10];
147
+  int number = 0; 
148
+  
149
+  
150
+  long previousMillis = 0;
151
+  //low limit
152
+  int limitebasse = 64;
153
+  int pas = 1;
154
+  
155
+  //decimal value for binary swtich
156
+  int valeur = 300;
157
+  int previousvaleur = 300;
158
+  int score = 0;
159
+  int previousscore = 0;
160
+  
161
+  char* _speed [4] = {"slow","normal","fast","hardcore"};
162
+  int Ispeed = 0;
163
+  char* bits[4] = {"4","5","6","8",};
164
+  int Ibits = 0;
165
+  char* help [2] = {"yes","no"};
166
+  int Ihelp = 0;  
167
+  
168
+  int highscore;
169
+  
170
+  
171
+  void setup()  {
172
+    pinMode(b1, INPUT);      
173
+    pinMode(b2, INPUT);      
174
+    pinMode(b4, INPUT);      
175
+    pinMode(b8, INPUT);      
176
+    pinMode(b16, INPUT);      
177
+    pinMode(b32, INPUT);      
178
+    pinMode(b64, INPUT);      
179
+    pinMode(b128, INPUT);      
180
+    pinMode(bhelp, INPUT);      
181
+    pinMode(bbutton, INPUT);      
182
+    pinMode(bbit1, INPUT);      
183
+    pinMode(bbit2, INPUT);      
184
+    pinMode(bspeed1, INPUT);      
185
+    pinMode(bspeed2, INPUT);      
186
+  
187
+    TV.start_render(_PAL);	//for devices with only 1k sram(m168) use TV.begin(_PAL,128,56)
188
+    TV.clear_screen();
189
+    //Serial.begin(9600);
190
+  }
191
+  
192
+  void loop() 
193
+  {
194
+    int _Ispeed = 100; 
195
+    boolean gameover = false;
196
+    int i = 0;
197
+    int maxbit = 4;
198
+    int help = 0;
199
+      
200
+    TV.clear_screen();
201
+     TV.print_str(0,8,"      TETALAB ");
202
+    TV.print_str(0,16,"    WE MAKE PORN");
203
+    TV.print_str(0,32,"  Binary Hero v0.91");
204
+    TV.print_str(0,48,"  Complex Solutions");
205
+    TV.print_str(0,56,"         to ");
206
+    TV.print_str(0,64," Inexistant problems");
207
+    delay(2000);
208
+  
209
+    TV.clear_screen();
210
+    menu(); 
211
+    TV.clear_screen();
212
+  
213
+    if (Ispeed == 0) _Ispeed = 200;
214
+    if (Ispeed == 1) _Ispeed = 100;
215
+    if (Ispeed == 2) _Ispeed = 50;
216
+    if (Ispeed == 3) _Ispeed = 25;
217
+  
218
+    if (Ibits == 0) maxbit = 15;
219
+    if (Ibits == 1) maxbit = 31;
220
+    if (Ibits == 2) maxbit = 63;
221
+    if (Ibits == 3) maxbit = 255;
222
+  
223
+    help = Ihelp;
224
+      
225
+    randomSeed(analogRead(5));
226
+    number = random(0,maxbit);
227
+   
228
+    TV.clear_screen();
229
+  
230
+  
231
+    //game init 
232
+    TV.draw_line(0,0,0,68,1);
233
+    TV.draw_line(0,0,35,0,1);
234
+    TV.draw_line(35,68,0,68,1);
235
+    TV.draw_line(35,68,35,0,1);
236
+    if (Ihelp == 0)
237
+    {    
238
+      TV.print_str(45,8,"Help:");
239
+    }
240
+    TV.print_str(45,32,"Bonus X");
241
+    TV.print_str(90,32,xx);
242
+    TV.print_str(45,56,"Score");
243
+    TV.print_str(82,56,"0");
244
+  
245
+  
246
+  
247
+    
248
+    while (!gameover)
249
+    {
250
+      if (millis() - previousMillis > _Ispeed) 
251
+      {
252
+        previousMillis = millis(); 
253
+        if (pas > limitebasse-2) 
254
+        {
255
+          TV.clear_screen();
256
+          TV.print_str(0,8,"      Game over");
257
+          TV.print_str(0,32,"       Score :");
258
+          //char charscore[4];
259
+          itoa(score,charscore,10);
260
+          TV.print_str(60,60,charscore);
261
+          int truc = 1;
262
+          delay(3000);
263
+          score = 0;
264
+          pas = 1;
265
+          number = random(0,maxbit);
266
+          TV.clear_screen();
267
+          gameover = true;
268
+        }
269
+        else
270
+        {
271
+          TV.draw_line(1,pas,34,pas,0);
272
+          pas++;
273
+       }
274
+      }
275
+  
276
+      itoa(number,charnum,10);
277
+      TV.print_str(10,pas,charnum);
278
+    
279
+      valeur = 0;
280
+      if (digitalRead(b1)==LOW) valeur = valeur+1;
281
+      if (digitalRead(b2)==HIGH) valeur = valeur+2;
282
+      if (digitalRead(b4)==HIGH) valeur = valeur+4;
283
+      if (digitalRead(b8)==HIGH) valeur = valeur+8;
284
+      if (digitalRead(b16)==HIGH) valeur = valeur+16;
285
+      if (digitalRead(b32)==HIGH) valeur = valeur+32;
286
+      if (digitalRead(b64)==HIGH) valeur = valeur+64;
287
+      if (digitalRead(b128)==HIGH) valeur = valeur+128;
288
+      
289
+      
290
+      
291
+      if (Ihelp == 0 && previousvaleur != valeur)
292
+      {    
293
+      
294
+        itoa(valeur,charhelp,10);
295
+        if (valeur<10) 
296
+        {
297
+          charhelp[2] = charhelp[0];
298
+          charhelp[1] = '0';
299
+          charhelp[0] = '0';
300
+        } 
301
+        if (valeur>9 && valeur<100) 
302
+        {
303
+          charhelp[2] = charhelp[1];
304
+          charhelp[1] = charhelp[0];
305
+          charhelp[0] = '0';
306
+        }
307
+        TV.print_str(75,8,charhelp);
308
+        previousvaleur = valeur;
309
+      }
310
+  
311
+  
312
+  
313
+  
314
+      if (score != previousscore)
315
+      {
316
+        itoa(score,charscore,10);
317
+        TV.print_str(82,56,charscore);
318
+        previousscore = score;
319
+      }
320
+  
321
+      if (valeur == number)
322
+      {
323
+        score = score + x;
324
+        number = random(0,maxbit);
325
+        
326
+        i = 0;
327
+        while (i < 8)
328
+        {
329
+          TV.draw_line(1,pas+i,34,pas+i,0);
330
+          i++;
331
+        }
332
+        TV.draw_line(35,68,0,68,1);
333
+        pas = 1;
334
+       }
335
+    }  
336
+  }
337
+  
338
+  
339
+  void displaymenu(int a,int b,int c)
340
+  {
341
+  //a = _speed
342
+  //b = bits
343
+  //c = help
344
+    TV.clear_screen();
345
+    TV.print_str(16,8, "Speed  :");
346
+    TV.print_str(16,16,"Nb bits:");
347
+    TV.print_str(16,24,"Help   :");
348
+    TV.print_str(12,40,"Press PAP to start");
349
+  
350
+    TV.print_str(65,8,_speed[a]);
351
+    TV.print_str(65,16,bits[b]);
352
+    TV.print_str(65,24,help[c]);
353
+  
354
+    x=0;
355
+    x = Ispeed + Ibits + Ihelp;
356
+    x = pow(2,x);
357
+  
358
+    itoa(x,xx,10);
359
+    TV.print_str(20,80,"Bonus : X");
360
+    TV.print_str(80,80,xx);
361
+  
362
+  }
363
+  
364
+  void  menu()
365
+  {
366
+    int i = 0;
367
+    boolean paplast = true;
368
+    displaymenu(Ispeed,Ibits,Ihelp);
369
+    
370
+    int lasthelp = 5;
371
+    int lastspeed = 5;
372
+    int lastbits = 5;
373
+         
374
+    while(i==0)
375
+    {
376
+      if (digitalRead(bhelp) == LOW) Ihelp = 0;
377
+      else Ihelp = 1;
378
+      
379
+      if ((Ihelp != lasthelp) || (Ibits != lastbits) || (Ispeed !=lastspeed))
380
+      {
381
+        displaymenu(Ispeed,Ibits,Ihelp);
382
+        lasthelp = Ihelp;
383
+        lastspeed = Ispeed;
384
+        lastbits = Ibits;
385
+      }
386
+      
387
+      if (digitalRead(bbit1) == HIGH && digitalRead(bbit2) == HIGH) Ibits = 0;
388
+      if (digitalRead(bbit1) == HIGH && digitalRead(bbit2) == LOW) Ibits = 1;
389
+      if (digitalRead(bbit1) == LOW && digitalRead(bbit2) == HIGH) Ibits = 2;
390
+      if (digitalRead(bbit1) == LOW && digitalRead(bbit2) == LOW) Ibits = 3;
391
+  
392
+      if (digitalRead(bspeed1) == HIGH && digitalRead(bspeed2) == HIGH) Ispeed = 0;
393
+      if (digitalRead(bspeed1) == HIGH && digitalRead(bspeed2) == LOW) Ispeed = 1;
394
+      if (digitalRead(bspeed1) == LOW && digitalRead(bspeed2) == HIGH) Ispeed = 2;
395
+      if (digitalRead(bspeed1) == LOW && digitalRead(bspeed2) == LOW) Ispeed = 3;
396
+      
397
+      if (digitalRead(bhelp) == HIGH) Ihelp = 1;
398
+      else Ihelp = 0;
399
+        
400
+      if (digitalRead(bbutton) == LOW) i = 1;
401
+    }
402
+  }