Byte-sequence version for use with kulifuli-host

This commit is contained in:
Reinout Meliesie 2025-08-23 19:56:06 +02:00
commit 7a66f55848
Signed by: zedfrigg
GPG key ID: 3AFCC06481308BC6

View file

@ -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 ;
}
}
}