Programming


The tentacle mechanism becomes animated based on what we tell it to do. We made some handy functions that will be useful to come up with some interesting combinations and behaviours!

The description of the functions below is organized by the tabs in the Arduino IDE from the example sketch. This makes it more organized than having all the functions in the main tab, and easier to look at than having to open up and edit a library. ;)


Demo Sketch

Here you can download the demo sketch to get your tentacle mechanism up and running!



Download Sketch

Two libraries are required: ShiftPWM & Streaming.

Be sure to download the libraries into your /Arduino/libraries folder and reboot the Arduino IDE. Here is a guide on how to install a library.


Pins

The pins used in the demo sketch are:
  • 4: Servo 0
  • 5: Tail LED 5
  • 6: Tail LED 4
  • 7: Servo 3
  • 8: Latch to Shift Out boards
  • 9: Servo 2
  • 10: Servo 1
  • 11: Shift Out MOSI ('Ser_In')
  • 12: Shift OUt SCK ('Clock')
  • A0: Sensor
This leaves pins 0, 1, 2, 3, 13, A1-A5 free for you to add on even more things. Also, you can add on more Shift Out boards and add extra LEDs or other outputs.


Onwards!

Now it is time to program interesting actions for your tentacle mechanism! The main behaviour that we came up with is distBehaviour, where it takes the current distance and behaves differently. You can add more on to this and make it do what you want it to!

Be


In the Be tab, all of these functions are various ways the body square LEDs can blink. Since we can associate emotions with colours, the functions are named for the emotions that the tentacle mechanism can emit.

void beExcited()
In this action, the tentacle blinks its LEDs in an 'excited' fashion. The two main colours here are red and green.

void beSurprised()
This is a good action for when you catch the tentacle by surprise. Its main colours are purple and white.

void beRelieved()
Here is when the tentacle was worried about something (like its distance sensor not detecting anyone ever again), but didn't happen in actuality. The main colours here are green.

void bePleased()
When something nice happens for the tentacle, it is pleased. The main colours for this action is purple and green.

void beConfused()
Sometimes the tentacle doesn't understand what is going on... in some sort of way. This would be a good action to express that, and its main colour is purple.

void beDiscontent()
The tentacle mechanism isn't exactly chirpy happy. Sniff sniff. The main colour is blue.

void beAngry()
Roooar!!! Something made the tentacle mechanism angry, uh oh! The main colour here is (you guessed it) red.

void beWondering()
With this action, the tentacle mechanism can adequately display what it looks like to wonder about the world. Or something like that. The main colours here are purple and blue.

void beTest()
This is a great function to run through all of the be actions — great for testing the square LEDs.

Dist


In this tab are the functions related to the distance behaviour. The main one is distBehaviour.

void distAction(uint8_t _distState)
This is mainly a helper function for distBehaviour. It controls the servos based on the current distance state.

void distActionTest()
Here is a test function you can use to run through all of the distance actions, to see how the tail can move!

void distBehaviour()
This is the main behaviour. It takes the current distance reading from the ultrasonic sensor, and performs the various tail movements and blinking of the LEDs.

Servos


There is only one function in this tab- but if you find any sequences of servo movements that you like you can put them here ;).

void wiggle(uint8_t ser, uint8_t rep, uint8_t del)
Wiggles the given servo back and forth. Servo number is specified by ser (0-4), wiggle repeat is given by rep and del is the delay between wiggles.

Square LEDs


Here in this tab are all the functions for controlling the LEDs on the main body square.

void squareColour(uint8_t led, uint8_t col, boolean beOn)


void squareOff()
Turns the entire square off.

void squareOn()
Turns the entire square on. void updateSquareRainbow()


void fadeSquare(uint8_t toVal, uint8_t stepTime)


void fadeSquareLed(uint8_t led, uint8_t col, uint8_t toVal, uint8_t stepTime)


void allSquareLeds(uint8_t r, uint8_t g, uint8_t b, uint8_t stepTime)


void fadeSquareLeds(uint8_t col, uint8_t toVal, uint8_t stepTime)


Tentacle LEDs


In this tab are all of the functions for controlling the tentacle tail LEDs.

void blinkTentacle(uint8_t rep, uint8_t del)
Blinks the tentacle tail (all LEDs) rep times. The delay period is between the states (off/on).

void chaseTentacle(uint8_t rep, uint8_t del)
Tentacle tail will 'chase' its LEDs rep times. The delay period is between the LEDs.

void fadeTentacle(uint8_t toVal, uint8_t stepTime)
Fades all of the LEDs on the tail to a given toVal from 0-255, 0 being darkest (off) and 255 being brightest (on). Step time is the delay between fade 'slices'. Smaller value = slower.

void tentacleOn()
Turns the entire tail on.

void tentacleOff()
Turns the entire tail off.

void fadeTentacleLed(uint8_t led, uint8_t toVal, uint8_t stepTime)
Fades a given LED on the tentacle tail. LED is specified with led, from 0-6. toVal is the given brightness from 0-255, 0 being darkest (off) and 255 being brightest (on). Step time is the delay between fade 'slices'. Smaller value = slower.

Ultrasonic


In this tab are all of the functions for controlling the tentacle tail LEDs.

uint8_t readDistance()
Returns the distance read from an ultrasonic sensor (connected on pingPin) in centimeters.

uint8_t microsecondsToCentimeters(long microseconds)
Helper function for taking ms and converting to cm.

Congrats!


You are have programmed Botbait! Yay! That is all for now. Go ahead and modify the tentacle even more to make it do crazy things!



"I programmed Botbait's tentacle mech! @RoboBrrd"
RoboBrrd Kit Building I programmed Botbait's tentacle mech! #RoboBrrd