Skip to content

Instantly share code, notes, and snippets.

@johnathanDOS
Created November 8, 2019 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnathanDOS/c6316ace455c844bd50b5cb07f594097 to your computer and use it in GitHub Desktop.
Save johnathanDOS/c6316ace455c844bd50b5cb07f594097 to your computer and use it in GitHub Desktop.
A bit of sample code that shows how Misty can read fingerprint scan data from an Arduino board through the UART serial port on her back.
// ----------------------- Finger Print Sensor -----------------
// Updates the fingerPrintActivated key to set the state of the skill
// so that Misty is ready to receive data from the fingerprint scanner
_enableFingerPrint()
function _enableFingerPrint() {
misty.Set("fingerPrintActivated", false, false);
}
// Starts Misty listening for data from UART serial. Data that comes in
// via serial is passed into the _backpackMessage callback.
_subscribeToBackpackData();
function _subscribeToBackpackData() {
misty.ChangeLED(0, 0, 255);
misty.DisplayImage("e_DefaultContent.jpg");
misty.AddReturnProperty("backpackMessage", "SerialMessage");
misty.RegisterEvent("backpackMessage", "SerialMessage", 50, true);
}
// Handles data passed in via serial.
function _backpackMessage(data) {
// Gets the message.
var status = data.AdditionalResults[0].Message;
// If "PASS", you're all set -- access granted!
if (status == "PASS") {
if (!misty.Get("fingerPrintActivated")) {
misty.Set("fingerPrintActivated", true, false);
misty.ChangeLED(0, 255, 0);
misty.DisplayImage("e_Joy2.jpg");
misty.PlayAudio("accessGranted.wav", 100);
misty.RegisterTimerEvent("resetEyes", 4000, false);
misty.RegisterTimerEvent("enableFingerPrint", 3000, false);
}
}
// If FAIL, Misty takes your picture. Access denied!
else if (status == "FAIL") {
if (!misty.Get("fingerPrintActivated")) {
misty.Set("fingerPrintActivated", true, false);
misty.Set("pictureUse", "FINGER", false);
misty.Set("pictureMode", true, false);
misty.DisplayImage("e_JoyGoofy.jpg");
misty.PlayAudio("accessDenied.wav", 100);
misty.ChangeLED(255, 0, 0);
misty.Pause(3000);
misty.DisplayImage("e_SystemFlash.jpg");
misty.ChangeLED(255, 255, 255);
misty.PlayAudio("s_SystemCameraShutter.wav", 100);
misty.TakePicture("finger", 375, 812, false, true);
misty.Pause(200);
misty.DisplayImage("e_SystemCamera.jpg");
misty.ChangeLED(140, 0, 255);
misty.Pause(500);
misty.RegisterTimerEvent("resetEyes", 3000, false);
misty.RegisterTimerEvent("enableFingerPrint", 3000, false);
}
}
catch (error) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment