Big Mouth Billy Bass automation library

Dependents:   BillyBass_with_SD

Committer:
bikeNomad
Date:
Thu Jun 20 15:03:49 2013 +0000
Revision:
8:ad0c038ebfc1
Parent:
7:dba9221acf48
Made main loop repeat forever; eliminated time shifting

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bikeNomad 0:84aaade0de8f 1 #ifndef __included_billybass_hpp
bikeNomad 0:84aaade0de8f 2 #define __included_billybass_hpp
bikeNomad 0:84aaade0de8f 3
bikeNomad 0:84aaade0de8f 4 #include "mbed.h"
bikeNomad 0:84aaade0de8f 5 #include "config.hpp"
bikeNomad 0:84aaade0de8f 6 #include <list>
bikeNomad 0:84aaade0de8f 7 #include <vector>
bikeNomad 0:84aaade0de8f 8 #include <cmath>
bikeNomad 3:6c91a6232c4a 9 #include "mbed_debug.h"
bikeNomad 0:84aaade0de8f 10
bikeNomad 0:84aaade0de8f 11 class BillyBass
bikeNomad 0:84aaade0de8f 12 {
bikeNomad 0:84aaade0de8f 13 public:
bikeNomad 0:84aaade0de8f 14
bikeNomad 3:6c91a6232c4a 15 BillyBass(PinName tailPin, PinName mouthPin, PinName bodyPin, bool _inverted=false) :
bikeNomad 3:6c91a6232c4a 16 tail(tailPin), mouth(mouthPin), body(bodyPin), inverted(!!_inverted) {
bikeNomad 3:6c91a6232c4a 17 relax();
bikeNomad 0:84aaade0de8f 18 if (numFish < MAX_FISH) fish[numFish++] = this;
bikeNomad 3:6c91a6232c4a 19 else fprintf(stderr, "Too many fish!\r\n");
bikeNomad 0:84aaade0de8f 20 }
bikeNomad 0:84aaade0de8f 21
bikeNomad 0:84aaade0de8f 22 // if *_pName, it will get the string name of the output
bikeNomad 7:dba9221acf48 23 DigitalOut *outputNamed(char const *_outputName, char const **_pName = 0, float *_pOnDelay = 0, float *_pOffDelay = 0, float *_pMinOn = 0);
bikeNomad 0:84aaade0de8f 24
bikeNomad 3:6c91a6232c4a 25 static BillyBass *bassNumber(unsigned which) {
bikeNomad 3:6c91a6232c4a 26 return (which >= numFish) ? 0 : fish[which];
bikeNomad 3:6c91a6232c4a 27 }
bikeNomad 3:6c91a6232c4a 28
bikeNomad 3:6c91a6232c4a 29 static unsigned getNumFish() {
bikeNomad 3:6c91a6232c4a 30 return numFish;
bikeNomad 3:6c91a6232c4a 31 }
bikeNomad 3:6c91a6232c4a 32
bikeNomad 3:6c91a6232c4a 33 int onState() const {
bikeNomad 3:6c91a6232c4a 34 return !inverted;
bikeNomad 3:6c91a6232c4a 35 }
bikeNomad 3:6c91a6232c4a 36 int offState() const {
bikeNomad 3:6c91a6232c4a 37 return inverted;
bikeNomad 3:6c91a6232c4a 38 }
bikeNomad 3:6c91a6232c4a 39
bikeNomad 3:6c91a6232c4a 40 void relax() {
bikeNomad 3:6c91a6232c4a 41 tail.write(offState());
bikeNomad 3:6c91a6232c4a 42 mouth.write(offState());
bikeNomad 3:6c91a6232c4a 43 body.write(offState());
bikeNomad 3:6c91a6232c4a 44 }
bikeNomad 4:f009306756b3 45 char const * outputName(DigitalOut const *out) const;
bikeNomad 0:84aaade0de8f 46
bikeNomad 0:84aaade0de8f 47 protected:
bikeNomad 0:84aaade0de8f 48 static BillyBass* fish[ MAX_FISH ];
bikeNomad 0:84aaade0de8f 49 static unsigned numFish;
bikeNomad 0:84aaade0de8f 50 static char const * mouthName;
bikeNomad 0:84aaade0de8f 51 static char const * bodyName;
bikeNomad 0:84aaade0de8f 52 static char const * tailName;
bikeNomad 0:84aaade0de8f 53
bikeNomad 0:84aaade0de8f 54 DigitalOut tail;
bikeNomad 0:84aaade0de8f 55 DigitalOut mouth;
bikeNomad 0:84aaade0de8f 56 DigitalOut body;
bikeNomad 3:6c91a6232c4a 57 int inverted;
bikeNomad 0:84aaade0de8f 58 };
bikeNomad 0:84aaade0de8f 59
bikeNomad 0:84aaade0de8f 60 #endif