From 7a66f55848d884b1f12dd939c32f8882e5693cb1 Mon Sep 17 00:00:00 2001 From: Reinout Meliesie Date: Sat, 23 Aug 2025 19:56:06 +0200 Subject: [PATCH] Byte-sequence version for use with kulifuli-host --- kulifuli-arduino.ino | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/kulifuli-arduino.ino b/kulifuli-arduino.ino index a87d8a6..e2ed9d5 100644 --- a/kulifuli-arduino.ino +++ b/kulifuli-arduino.ino @@ -1,6 +1,3 @@ -bool fanControlEntered = 0 ; - - void setup () { Serial . begin (9600) ; @@ -59,26 +56,35 @@ void setup () { } +// Sequence is 188 92 136 14 154 39 154 139 {duty-cycle} + +int seqPos = 0 ; + void loop () { if ( Serial . available () ) { - if (fanControlEntered) { - int dutyCyclePercent = Serial . parseInt () ; - int dutyCycle = map ( dutyCyclePercent , 0 , 100 , 0 , 79 ) ; - OCR1AL = dutyCycle ; - OCR1BL = dutyCycle ; - Serial . read () ; // Consume newline + int input = Serial . read () ; - Serial . print ("duty-cycle ") ; - Serial . print (dutyCycle) ; - Serial . print ('\n') ; + if ( + seqPos == 0 && input == 188 || + seqPos == 1 && input == 92 || + seqPos == 2 && input == 136 || + seqPos == 3 && input == 14 || + seqPos == 4 && input == 154 || + seqPos == 5 && input == 39 || + seqPos == 6 && input == 154 || + seqPos == 7 && input == 139 + ) { + // Advance in the sequence + seqPos ++ ; + } else if ( seqPos == 8 ) { + // `input` is the new duty cycle + OCR1AL = input ; + OCR1BL = input ; + Serial . write (input) ; + seqPos = 0 ; } else { - String input = Serial . readString () ; - if ( input == "enter-fan-control" ) { - fanControlEntered = 1 ; - Serial . println ("success") ; - } else { - Serial . println ("error") ; - } + // Reset sequence progress + seqPos = 0 ; } } }