From fd76bd7de910cc31b28ee3e099bdd770321cb37b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20L=C3=B8vbr=C3=B8tte=20Olsen?= Date: Thu, 5 Apr 2018 14:15:52 +0200 Subject: [PATCH] Add function to shiftout n size numbers instead of just bytes --- School/vg2/Yahzee/yahzee.ino | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/School/vg2/Yahzee/yahzee.ino b/School/vg2/Yahzee/yahzee.ino index ed5f13f..cbf3b38 100644 --- a/School/vg2/Yahzee/yahzee.ino +++ b/School/vg2/Yahzee/yahzee.ino @@ -14,6 +14,7 @@ int toDice(int n); unsigned long int shift(int* numbers); +void ShiftNOut(unsigned long int value, byte n) uint8_t dicerolls[DICEN]; @@ -53,9 +54,7 @@ void loop() { dicerolls[4] = random(1, 7); } unsigned long int result = shift(dicerolls) - /*shiftOut(result >> 16); - shiftOut(result >> 8); - shiftOut(result);*/ + ShiftNOut(result, sizeof(long)) } } @@ -104,3 +103,10 @@ unsigned long int shift(int* numbers) { return shiftn; /* End result is a number representing your data outputs for all DICEN */ } + +void ShiftNOut(unsigned long int value, byte n) { + n = n/sizeof(byte); + for (byte i = 0; i < n; i++) { + ShiftOut(value >> sizeof(byte)*i) + } +}