30 likes | 76 Views
Warmup – 21 FEB2012. Arduino. This one is for practice . I have paper if you need it .
E N D
Warmup – 21FEB2012 Arduino This one is for practice. I have paper if you need it. Create a function in C that takes as its argument an Arduino pin number and returns HIGH or LOW depending on the digital value of the pin state (HIGH or LOW, respectively). In other words, if the digital value of Arduino pin 3 is LOW, your function returns LOW, else if the pin is HIGH, your function returns HIGH. Pxn Px0
Solution – Arduino Style intdig_test ( intpin_no ) { if ( ( (pin_no >= 0) && (pin_no <= 19) ) ) { return (digitalRead( pin_no ) ); } else { return (-1); } }
Solution – PORT Style intdig_test ( intpin_no ) { if ( ( (pin_no >= 0) && (pin_no <= 19) ) ) { if pin_no in 0-7, then PORTD if pin_no in 8-13, then PORTB if pin_no in 14-19, then PORTC return (digitalRead( pin_no ) ); } else { return (-1); } }