Controlling outputs on the CC1 (Buzzer/Vibration/LED)

The CC1 has several ‘outputs’ which can be used to interact with its environment. In this post I will look at 3 of these that use a similar method to control their output : the buzzer, the vibration motor and the LED.

To control an output, we send a MQTT JSON message to the device, referencing the ‘dev’ app (ie the device as a whole) and these specific output. These are ‘buzzer’, ‘vibration’ and ‘led’ here. Multiple outputs can be set in the same message. For example

{
	"app":{
		"dev":{
			"buzzer":{ "song":"bb01c-01ab01Ab05Eb10"}			
		}
      }
}

This tells the buzzer to play a “song” ie a sequence of notes, each with a specific tone and duration. The ‘song’ is played in the background on the device until it reaches the end of the string. This ‘song’ idea is used for all 3 devices - only the data is specific to each output.

Buzzer: the song is composed iof groups of 4 characters : ‘nmdd’ . ‘n’ is the note eg ‘b’ for a middle B, ‘m’ is the modifier (sharp ‘#’, flat ‘b’, ‘-’ or ’ ’ for natural) and ‘dd’ is the duration in 1/10s. So bb01 means play middle B flat for 0.1s. When ‘n’ is ‘S’ this is a silence or rest. Some special characters allow to access specific high pitched tones (see the reference doc)

Vibration : the groups are 3 characters, ‘Odd’ : O is either ‘V’ to vibrate or ‘S’ for silence and ‘dd’ is the duration in 1/10s.

LED : the groups are 5 characters: ‘rgbdd’. Each of ‘r’, ‘g’, ‘b’ is the decimal 0-9 to set the intensity of the Red, Green or Blue component, and ‘dd’ is the duration in 1/10s again.

An example with all the outputs:

{
  "app":{
    "dev":{
      "buzzer":{ "song":"bb01c-01ab01Ab05Eb10"},
      "led":{ "song":"100012000130001900010100102001090010010100201003010090199910"},
     "vibration":{ "song":"V10S01V10S01V10S01V10"}
    }
  }
}