/* Bulls and Cows with Sleep v2 David Johnson-Davies - www.technoblogy.com - 5th April 2015 CC BY 4.0 Licensed under a Creative Commons Attribution 4.0 International license: http://creativecommons.org/licenses/by/4.0/ */ #include #define adc_disable() (ADCSRA &= ~(1<> 1; } charArray[i]=newsegs; } } void DisplayNextDigit() { char segs, row; pinMode(Digits[digit], INPUT); digitalWrite(Digits[digit], LOW); digit = (digit+1) % Ndigits; segs = charArray[Buffer[digit]]; // Decimal points if ((dp & 1<=0 ; d--) { Buffer[d]=i % 10; i = i / 10; } dp = 1<<3; } // Display message void ShowMessage (int message) { for (int d=0; d<6 ; d++) Buffer[d]=message + d; dp = 0; WaitForGo(); } void ClearDisplay () { for (int d=0; d<6 ; d++) Buffer[d] = Space; // Show all decimal points dp = 0x3F; } // Timer interrupt - multiplexes display ISR (TIMER1_COMPA_vect) { DisplayNextDigit(); } // Handle sleep ********************************************** void Sleep () { // Turn off display multiplexing TIMSK1 &= ~(1< TimeToSleep) { Sleep(); time = millis(); } } while (Key() == 0); } void WaitKeyUp() { do ; while (Key() != 0); } // Read a four-digit guess or two-digit reply, display and return it int Read (int length) { int key, first; if (length == 4) first = 0; else first = 4; int last = first + length; do { int d = first, result = 0; for (int d=first; d= 0) cows++; } a = a / 10; b = b / 10; } return bulls*10 + cows; } // Setup and main loop ********************************************** void setup() { ReorderBits(); // Set up Timer1 to multiplex the display TCCR1A = 0<