Byte-sequence version for use with kulifuli-host
This commit is contained in:
parent
6da8d10f84
commit
7a66f55848
1 changed files with 25 additions and 19 deletions
|
@ -1,6 +1,3 @@
|
||||||
bool fanControlEntered = 0 ;
|
|
||||||
|
|
||||||
|
|
||||||
void setup () {
|
void setup () {
|
||||||
Serial . begin (9600) ;
|
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 () {
|
void loop () {
|
||||||
if ( Serial . available () ) {
|
if ( Serial . available () ) {
|
||||||
if (fanControlEntered) {
|
int input = Serial . read () ;
|
||||||
int dutyCyclePercent = Serial . parseInt () ;
|
|
||||||
int dutyCycle = map ( dutyCyclePercent , 0 , 100 , 0 , 79 ) ;
|
|
||||||
OCR1AL = dutyCycle ;
|
|
||||||
OCR1BL = dutyCycle ;
|
|
||||||
Serial . read () ; // Consume newline
|
|
||||||
|
|
||||||
Serial . print ("duty-cycle ") ;
|
if (
|
||||||
Serial . print (dutyCycle) ;
|
seqPos == 0 && input == 188 ||
|
||||||
Serial . print ('\n') ;
|
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 {
|
} else {
|
||||||
String input = Serial . readString () ;
|
// Reset sequence progress
|
||||||
if ( input == "enter-fan-control" ) {
|
seqPos = 0 ;
|
||||||
fanControlEntered = 1 ;
|
|
||||||
Serial . println ("success") ;
|
|
||||||
} else {
|
|
||||||
Serial . println ("error") ;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue