-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNameBadge.ino
704 lines (638 loc) · 18.3 KB
/
NameBadge.ino
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
/*
* Name Badge
*
* Displays a name badge.
*
* When using Spence Konde's ATTinyCore https://github.com/SpenceKonde/ATTinyCore
* and using a chip without Optiboot, with LTO enabled, this sketch takes 8054 bytes of flash.
*
* The Name Badge contains 5 screens
* A screen is a list of 16 items
* An item is a portion of a text string shown in a particular location, font, and font size.
* The text string is able to be up to 256 characters long.
*
* The details are stored in EEPROM
*
* Menu system
* -----------
* Single button menu system to support editing every detail.
* A short press on the button changes selection, a long press on the button actions the selection.
* A second button is also supported, and a short press on the second button actions the selection.
*
* 4 fonts:
* 6x8
* 8x16
* Menu Icons
* Graphics
*
* Power on:
* set up buttons
* Load contrast from EEPROM
* Load current screen number from EEPROM
* Display current screen
* turn on screen
* Go to sleep till a button is pressed.
*
*/
#include <avr/sleep.h>
#include <EEPROM.h>
#include <TinyI2CMaster.h>
#include <Tiny4kOLED.h>
#include "eeprom_contents.h"
#include "symbol_font.h"
#include "graphics_font.h"
#include "menus.h"
// Routines to set and clear bits (used in the sleep code)
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
const DCfont * const fonts[] PROGMEM = { FONT6X8, FONT8X16, &symbolFont, &graphicFont };
static bool eepromOk = false;
static uint8_t currentContrast = 16;
static uint8_t currentScreen = 0;
static uint8_t currentScreenItem;
static uint8_t currentMode = 0;
static uint8_t lastMode = 0;
static uint8_t numMenuItems;
static MenuItem * menuItems;
static uint8_t menuLine;
static uint8_t itemLocationX;
static uint8_t itemLocationY;
static uint8_t itemFontNum;
static const DCfont * itemFont;
static uint8_t itemDoubleSize;
static uint8_t itemOffset;
static uint16_t itemAddress;
static uint8_t itemLength;
static uint8_t currentItemCharacterPos;
static uint8_t currentLetter;
#define MAIN_BUTTON 4
#define ENTER_BUTTON 1
static bool mainButtonWasDown = false;
static bool enterButtonWasDown = false;
static bool longPressActioned = false;
static long buttonDownTime;
#define LONG_PRESS_REPEAT 500L
ISR(PCINT0_vect) {}
void setup() {
setupADC();
setupInputs();
setupOLED();
setupFromEEPROM();
oled.setContrast(currentContrast);
displayScreenForMode();
oled.on();
}
static void setupADC() {
ADMUX = 0b1100<<MUX0; // Vcc Ref, Measure bandgap voltage (1.1)
ADCSRA = 1<<ADEN | 4<<ADPS0; // Enable, 62.5kHz ADC clock (16x prescalar)
}
void setupInputs() {
pinMode(MAIN_BUTTON, INPUT_PULLUP);
pinMode(ENTER_BUTTON, INPUT_PULLUP);
GIMSK = 1 << PCIE; // Enable pin-change interrupt
PCMSK = (1 << MAIN_BUTTON) | (1 << ENTER_BUTTON);
}
void setupOLED(void) {
oled.begin(128, 64, sizeof(tiny4koled_init_128x64br), tiny4koled_init_128x64br);
}
static void setupFromEEPROM() {
eepromOk = EEPROM.read(NAMEBADGE_MAGIC_ADDRESS ) == NAMEBADGE_MAGIC0 &&
EEPROM.read(NAMEBADGE_MAGIC_ADDRESS + 1) == NAMEBADGE_MAGIC1 &&
EEPROM.read(NAMEBADGE_MAGIC_ADDRESS + 2) == NAMEBADGE_MAGIC2 &&
EEPROM.read(NAMEBADGE_MAGIC_ADDRESS + 3) == NAMEBADGE_MAGIC3;
if (eepromOk) {
currentScreen = EEPROM.read(NAMEBADGE_CURRENT_SCREEN_ADDRESS);
currentContrast = EEPROM.read(NAMEBADGE_CONTRAST_ADDRESS);
} else {
currentMode = SETTINGS_MENU_MODE;
}
}
static void displayScreenForMode() {
numMenuItems = pgm_read_byte(&(menus[currentMode].numItems));
menuItems = pgm_read_word(&(menus[currentMode].items));
((DisplayFunc)pgm_read_ptr(&(menus[currentMode].displayFn)))();
if (numMenuItems > 0) {
redrawMenuCursor();
}
}
void loop() {
processButtonInputs();
if (!processButtonInputs()) {
system_sleep();
}
}
bool processButtonInputs(void) {
bool mainButtonIsDown = digitalRead(MAIN_BUTTON) == LOW;
if (mainButtonIsDown) {
if (mainButtonWasDown) {
long buttonDownDuration = millis() - buttonDownTime;
if (buttonDownDuration >= LONG_PRESS_REPEAT) {
buttonDownTime = millis();
longPress();
longPressActioned = true;
}
} else {
mainButtonWasDown = true;
buttonDownTime = millis();
}
} else {
if (mainButtonWasDown && !longPressActioned) {
long buttonDownDuration = millis() - buttonDownTime;
if (buttonDownDuration < LONG_PRESS_REPEAT) {
shortPress();
} else {
longPress();
}
}
mainButtonWasDown = false;
longPressActioned = false;
}
bool enterButtonIsDown = digitalRead(ENTER_BUTTON) == LOW;
if (enterButtonIsDown) {
enterButtonWasDown = true;
} else {
if (enterButtonWasDown) {
enterButtonWasDown = false;
longPress();
}
}
return mainButtonIsDown || enterButtonIsDown;
}
static void shortPress() {
if (currentMode == 0) {
nextScreenAction();
} else {
nextMenuItemAction();
}
displayScreenForMode();
}
static void longPress() {
if (currentMode == 0) {
if (currentScreen > 0) {
showMenuAction();
} else {
nextScreenAction();
}
} else {
invokeMenuItemAction();
}
displayScreenForMode();
}
static void nextMenuItemAction(void) {
menuLine++;
if (menuLine > numMenuItems) menuLine = 0;
}
static void invokeMenuItemAction(void) {
if (menuLine == 0) {
if (eepromOk) {
currentMode = pgm_read_byte(&(menus[currentMode].exitMode));
}
} else {
indicateWorking(); // some actions take a while
((ActionFunc)pgm_read_ptr(&(menuItems[menuLine - 1].actionFn)))();
}
}
void drawScreen(void) {
oled.clear();
currentScreenItem = 0;
currentItemChanged();
do {
displayItem();
nextItemAction();
} while (currentScreenItem != 0);
}
static void displayItem(void) {
if (itemLength == 0) return;
itemFont = (const DCfont *)pgm_read_ptr(&fonts[itemFontNum]);
oled.setFont(itemFont);
if (itemDoubleSize) {
for (uint8_t pageLine = 0; pageLine < itemFont->height * 2; pageLine++) {
oled.setCursor(itemLocationX, itemLocationY + pageLine);
oled.startData();
for (uint8_t offset = 0; offset < itemLength; offset++) {
uint8_t c = EEPROM.read(itemAddress + offset);
c = limitToFont(c);
uint16_t bitmapOffset = itemFont->width * (itemFont->height * (c - itemFont->first) + (pageLine >> 1));
uint8_t * cPtr = &(itemFont->bitmap[bitmapOffset]);
uint8_t i = itemFont->width;
do {
uint8_t b = pgm_read_byte(cPtr++);
if ((pageLine & 0x01) == 0x01) {
b = b >> 4;
}
b = ((b & 8) << 3) | ((b & 4) << 2) | ((b & 2) << 1) | (b & 1);
b += b << 1;
oled.sendData(b);
oled.sendData(b);
}
while (--i);
}
oled.endData();
}
} else {
outputCurrentTextAt(itemLocationX, itemLocationY, 0, itemLength);
}
}
static void nextScreenAction() {
currentScreen++;
if (currentScreen >= NUMBER_OF_SCREENS) currentScreen = 0;
EEPROM.write(NAMEBADGE_CURRENT_SCREEN_ADDRESS, currentScreen);
}
static void showMenuAction(void) {
switchToMode(ITEM_SELECTION_MODE);
}
static void displayMenu() {
if (currentMode != lastMode) {
oled.clear();
lastMode = currentMode;
}
oled.setCursor(0,1);
oled.fillLength(0x18, 120);
for (uint8_t l = 0; l < numMenuItems; l++) {
redrawMenuLine(l);
}
oled.setCursor(0,7);
oled.fillLength(0x18, 120);
}
static void redrawMenuLine(uint8_t l) {
oled.setFont(FONT6X8);
oled.setCursor(0, 2 + l);
PGM_P namePtr = pgm_read_word(&(menuItems[l].name));
if (namePtr != NULL) {
oled.print(FPSTR(pgm_read_word(&(menuItems[l].name))));
}
}
static void redrawMenuCursor(void) {
for (uint8_t p = 0; p < 8; p++) {
oled.setCursor(120,p);
oled.fillLength(0x00,8);
}
oled.setFont(&symbolFont);
if (menuLine == 0) {
oled.setCursor(120,0);
oled.write(CLOSE_MENU_SYMBOL);
} else {
oled.setCursor(120,menuLine + 1);
oled.write(ACTIVE_MENU_SYMBOL);
}
}
static void indicateWorking(void) {
oled.setCursor(120,menuLine + 1);
oled.write(WORKING_SYMBOL);
}
static void switchToMode(uint16_t m) {
currentMode = m;
menuLine = 0;
oled.clear();
displayScreenForMode();
}
static uint8_t getCurrentItemAddress(void) {
return NAMEBADGE_ITEM_BASE_ADDRESS + currentScreen * ITEMS_PER_SCREEN * BYTES_PER_ITEM + currentScreenItem * BYTES_PER_ITEM;
}
static void currentItemChanged(void) {
currentScreenItem &= 0x0F;
uint8_t offset = getCurrentItemAddress();
uint8_t nextLocation = EEPROM.read(offset++);
uint8_t nextOffset = EEPROM.read(offset++);
uint8_t nextDetail = EEPROM.read(offset++);
decodeItem(nextLocation, nextOffset, nextDetail);
}
static void decodeItem(uint8_t nextLocation, uint8_t nextOffset, uint8_t nextDetail) {
itemLocationX = nextLocation & 0x78;
itemLocationY = nextLocation & 0x07;
itemOffset = nextOffset;
itemAddress = NAMEBADGE_TEXT_BASE_ADDRESS + itemOffset;
itemDoubleSize = (nextDetail & 0x80);// == 0x80;
itemFontNum = (nextDetail & 0x60) >> 5;
itemLength = nextDetail & 0x1F;
}
static void saveItem(void) {
uint8_t offset = getCurrentItemAddress();
EEPROM.write(offset++, itemLocationX | itemLocationY);
EEPROM.write(offset++, itemOffset);
EEPROM.write(offset++, (itemDoubleSize/* ? 0x80 : 0x00*/) | (itemFontNum << 5) | itemLength);
itemAddress = NAMEBADGE_TEXT_BASE_ADDRESS + itemOffset;
}
static void outputCurrentTextAt(uint8_t x, uint8_t y, uint8_t initialOffset, uint8_t displayedLength) {
oled.setCursor(x,y);
for (uint8_t offset = initialOffset; (offset < itemLength) && ((offset - initialOffset) < displayedLength); offset++) {
uint8_t c = EEPROM.read(itemAddress + offset);
c = limitToFont(c);
oled.write(c);
}
}
static void preview() {
displayItem();
saveItem();
delay(400);
oled.clear();
}
void drawItemMenu(void) {
displayMenu();
oled.setFont(FONT6X8);
oled.setCursor(0,0);
oled.print(FPSTR(ITEM_NAME));
if (currentScreenItem < 9) {
oled.write(' ');
}
oled.print(currentScreenItem + 1);
oled.write(',');
outputCurrentTextAt(48, 0, 0, 12);
for (uint8_t filler = itemLength; filler <= 12; filler++) {
oled.write(' ');
}
}
void nextItemAction(void) {
currentScreenItem++;
currentItemChanged();
}
void prevItemAction(void) {
currentScreenItem--;
currentItemChanged();
}
void selectTextAction(void) {
if (itemLength == 0 && itemOffset == 0) {
itemOffset = RESERVED_TEXT;
}
switchToMode(SELECT_TEXT_MODE);
}
void editItemAction(void) {
if (itemLength == 0) return;
switchToMode(EDIT_ITEM_MODE);
}
void settingsAction(void) {
switchToMode(SETTINGS_MENU_MODE);
}
void changeLocationAction(void) {
switchToMode(CHANGE_LOCATION_MODE);
}
void changeFontAction(void) {
itemFontNum++;
itemFontNum &= 3;
preview();
}
void changeSizeAction(void) {
itemDoubleSize ^= 0x80; //!itemDoubleSize;
preview();
}
void alterTextAction(void) {
switchToMode(TEXT_EDIT_OPTIONS_MODE);
}
void locationLeftAction(void) {
if (itemLocationX > 0) {
itemLocationX -= 8;
preview();
}
}
void locationRightAction(void) {
if (itemLocationX < 120) {
itemLocationX += 8;
preview();
}
}
void locationUpAction(void) {
if (itemLocationY > 0) {
itemLocationY--;
preview();
}
}
void locationDownAction(void) {
if (itemLocationY < 7) {
itemLocationY++;
preview();
}
}
void drawSelectTextMenu(void) {
drawItemMenu();
showTextSelection(0, itemLength > 0 ? itemLength - 1 : 0);
}
void selectTextLeftAction(void) {
if (itemOffset > RESERVED_TEXT) {
itemOffset--;
saveItem();
}
}
void selectTextRightAction(void) {
if (itemOffset < 256 - itemLength) {
itemOffset++;
saveItem();
}
}
void selectTextLongerAction(void) {
if ((itemLength < 31) && (itemOffset < 256 - itemLength)) {
itemLength++;
saveItem();
}
}
void selectTextShorterAction(void) {
if (itemLength > 0) {
itemLength--;
saveItem();
}
}
void drawTextEditOptionsMenu(void) {
drawItemMenu();
showTextSelection(currentItemCharacterPos, currentItemCharacterPos);
}
static void showTextSelection(uint8_t startPos, uint8_t endPos) {
oled.setFont(FONT6X8);
outputCurrentTextAt(12, 6, 0, itemLength); // todo scroll
oled.setCursor(8,7);
oled.fillLength(0x18, 112);
oled.setFont(&symbolFont);
oled.setCursor(11 + 6 * startPos, 7);
oled.write(SELECTED_LETTER_SYMBOL);
oled.setCursor(11 + 6 * endPos, 7);
oled.write(SELECTED_LETTER_SYMBOL);
}
void textEditLeftAction(void) {
if (currentItemCharacterPos > 0) {
currentItemCharacterPos--;
currentLetter = EEPROM.read(itemAddress + currentItemCharacterPos);
}
}
void textEditRightAction(void) {
if (currentItemCharacterPos < itemLength - 1) {
currentItemCharacterPos++;
currentLetter = EEPROM.read(itemAddress + currentItemCharacterPos);
}
}
void textEditAction(void) {
switchToMode(TEXT_EDIT_MODE);
}
void textEditInsertDeleteAction(void){
switchToMode(TEXT_INSERT_DELETE_MODE);
}
static uint8_t limitToFont(uint8_t c) {
if (c > itemFont->last) {
c = itemFont->first;
}
if (c < itemFont->first) {
c = itemFont->last;
}
return c;
}
void textEditNextAction(void) {
currentLetter++;
updateCurrentLetter();
}
void textEditPrevAction(void) {
currentLetter--;
updateCurrentLetter();
}
static void updateCurrentLetter(void) {
currentLetter = limitToFont(currentLetter);
EEPROM.write(itemAddress + currentItemCharacterPos, currentLetter);
}
void drawTextInsertDeleteMenu(void) {
drawItemMenu();
showTextSelection(currentItemCharacterPos, currentItemCharacterPos);
}
void textInsertAction(void) {
if (itemLength == 31) return;
// All items that start after get shifted. All items that start before and end on or after get lengthened
commonInsertDeleteAction(false);
}
void textDeleteAction(void) {
if (itemLength == 0) return;
// All items that start after get shifted. All items that start before and end on or after get shortened
commonInsertDeleteAction(true);
}
void commonInsertDeleteAction(bool deleting) {
uint8_t insertPosition = itemOffset + currentItemCharacterPos;
uint8_t s = currentScreen;
uint8_t i = currentScreenItem;
for (currentScreen = 0; currentScreen < NUMBER_OF_SCREENS; currentScreen++) {
for (uint8_t item = 0; item < ITEMS_PER_SCREEN; item++) {
currentScreenItem = item;
currentItemChanged();
if (itemOffset <= insertPosition) {
if (itemOffset + itemLength > insertPosition) {
if (deleting) {
selectTextShorterAction();
} else {
selectTextLongerAction();
}
}
} else {
if (deleting) {
selectTextLeftAction();
} else {
if ((uint16_t)itemOffset + itemLength >= 256) {
selectTextShorterAction();
}
selectTextRightAction();
}
}
}
}
// All the characters get shifted.
if (deleting) {
for (uint16_t p = NAMEBADGE_TEXT_BASE_ADDRESS + insertPosition; p < 511; p++) {
uint8_t c = EEPROM.read(p + 1);
EEPROM.write(p, c);
}
} else {
for (uint16_t p = 511; p >= NAMEBADGE_TEXT_BASE_ADDRESS + (uint16_t)insertPosition + 1; p--) {
uint8_t c = EEPROM.read(p - 1);
EEPROM.write(p, c);
}
}
currentScreen = s;
currentScreenItem = i;
currentItemChanged();
}
void drawSettingsMenu(void) {
displayMenu();
oled.setFont(FONT6X8);
oled.setCursor(0,0);
oled.print(FPSTR(SETTINGS_NAME));
oled.write(' ');
outputVoltage();
}
void settingsIncreaseContractAction(void) {
// It can wrap to 0
currentContrast++;
setContrast();
}
void settingsDecreaseContractAction(void) {
// It can wrap to 255
currentContrast--;
setContrast();
}
static void setContrast(void) {
oled.setContrast(currentContrast);
if (eepromOk) {
EEPROM.write(NAMEBADGE_CONTRAST_ADDRESS, currentContrast);
}
}
void settingsResetAction(void) {
// EEPROM Header
for (uint16_t offset = 0; offset < sizeof(header); offset++) {
EEPROM.write(offset, pgm_read_byte(&header[offset]));
}
// Unused
for (uint16_t address = sizeof(header); address < 256; address++) {
EEPROM.write(address, 0);
}
// Item Definitions
uint16_t screenItemOffset = NAMEBADGE_ITEM_BASE_ADDRESS;
for (uint16_t offset = 0; offset < sizeof(screenItems0); offset++) {
EEPROM.write(screenItemOffset + offset, pgm_read_byte(&screenItems0[offset]));
}
uint16_t screenItemsSize = ITEMS_PER_SCREEN * BYTES_PER_ITEM;
screenItemOffset += screenItemsSize;
for (uint16_t offset = 0; offset < sizeof(screenItems1); offset++) {
uint8_t itemByte = pgm_read_byte(&screenItems1[offset]);
EEPROM.write(screenItemOffset + offset, itemByte);
}
screenItemOffset += screenItemsSize;
for (uint16_t offset = 0; offset < sizeof(screenItems2); offset++) {
uint8_t itemByte = pgm_read_byte(&screenItems2[offset]);
EEPROM.write(screenItemOffset + offset, itemByte);
}
screenItemOffset += screenItemsSize;
for (uint16_t offset = 0; offset < sizeof(screenItems3); offset++) {
uint8_t itemByte = pgm_read_byte(&screenItems3[offset]);
EEPROM.write(screenItemOffset + offset, itemByte);
}
// Item Contents
for (uint16_t offset = 0; offset < 256; offset++) {
char c = ' ';
if (offset < sizeof(textContents)) {
c = pgm_read_byte(&textContents[offset]);
}
EEPROM.write(NAMEBADGE_TEXT_BASE_ADDRESS + offset, c);
}
eepromOk = true;
currentScreen = 0;
switchToMode(DRAW_SCREEN_MODE);
}
static void outputVoltage(void) {
uint16_t result = readADC();
result = 1126400L / result; // Calculate Vcc (in mV); 1.1*1024*1000
// A very rough estimate saves 54 bytes:
//result = 6100 - 8 * result;
oled.print(result);
oled.print(F(" mV"));
}
static uint16_t readADC() {
uint8_t low,high;
ADCSRA = ADCSRA | 1<<ADSC; // Start
do {} while (ADCSRA & 1<<ADSC); // Wait while conversion in progress
low = ADCL;
high = ADCH;
return ((uint16_t)high<<8 | low);
}
void system_sleep() {
cbi(ADCSRA,ADEN); // switch Analog to Digitalconverter OFF
set_sleep_mode(SLEEP_MODE_PWR_DOWN); // sleep mode is set here
sleep_enable();
sleep_mode(); // System actually sleeps here
sleep_disable(); // System continues execution here when watchdog timed out
sbi(ADCSRA,ADEN); // switch Analog to Digitalconverter ON
}