collab/pb-hal
git clone https://git.julia.blue/collab/pb-hal
1dbe808
control
1#include <RASLib/inc/common.h> 2#include <RASLib/inc/gpio.h> 3#include <RASLib/inc/time.h> 4 5#include <RASLib/inc/pwm.h> 6 7#include <stdint.h> 8 9// Blink the LED to show we're on 10tBoolean blink_on = true; 11 12#define IN1 PIN_D1 13#define IN2 PIN_D2 14 15#define min (a ,b ) ((a) <= (b) ? (a) : (b)) 16#define max (a ,b ) ((a) >= (b) ? (a) : (b)) 17 18tPWM * uno ,* dos ; 19int8_t speed ; 20 21#define SCALE_LEN 5 22 23static const char scale [2 * SCALE_LEN + 1 ]= "asdfghjkl;'" ; 24 25 26void blink (void ) 27{ 28SetPin (PIN_F3 ,blink_on ); 29blink_on = !blink_on ; 30} 31 32void setOutputs (const int8_t set ) 33{ 34// If set is below 0, go in direction of IN1: 35SetPWM (uno ,- min (set /128.0 ,0 ),0 ); 36SetPWM (dos ,max (set /128.0 ,0 ),0 ); 37} 38 39int8_t getSpeed (char c ) 40{ 41int8_t step = 127 / (SCALE_LEN ), 42speed = - (SCALE_LEN ); 43 44while (speed <=SCALE_LEN ) 45 { 46if (scale [speed + SCALE_LEN ]== c ) 47break ; 48 49speed ++ ; 50 } 51 52return speed * step ; 53} 54 55int main (void ) 56{ 57CallEvery (blink ,0 ,0.5 ); 58 59InitializeUART (115200 ); 60 61uno = InitializePWM (IN1 ,200 ); 62dos = InitializePWM (IN2 ,200 ); 63 64setOutputs (0 ); 65int8_t set ; 66 67 68while (true) { 69 70Printf ("Speed? " ); 71 72set = getSpeed (Getc ()); 73Printf ("%d\n" ,set ,set ); 74Printf ("%f & %f\n\n" ,- min (set /128.0 ,0 ),max (set /128.0 ,0 )); 75 76setOutputs (set ); 77 } 78}