Skip to content

Instantly share code, notes, and snippets.

@jenschr
Created April 3, 2018 14:45
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 jenschr/06acd0e933bf211df31311fa3252e077 to your computer and use it in GitHub Desktop.
Save jenschr/06acd0e933bf211df31311fa3252e077 to your computer and use it in GitHub Desktop.
Simple code snippet to blink lights and produce a siren for Makeblock's mBot. Please credit if re-distributing this code
// Simple code snippet to blink lights and produce a siren for Makeblock's mBot.
// Author: @jenschr / Jensa
// Please credit if re-distributing this code
#include <MeMCore.h>
MeRGBLed rgb(PORT_7);
int highestPitch = 3500;
int lowestPitch = 640;
int toneRightNow = lowestPitch;
boolean isTheToneMovingUpwards = true;
int sequence = 0;
int tempo = 150;
void setup() {
}
void loop() {
if( isTheToneMovingUpwards ){
toneRightNow += tempo;
} else {
toneRightNow -= tempo;
}
if( toneRightNow > highestPitch ){
isTheToneMovingUpwards = false;
} else if( toneRightNow < lowestPitch ){
isTheToneMovingUpwards = true;
sequence++;
}
tone(8, toneRightNow,6);
delay(8);
noTone(8);
delay(2);
if( (toneRightNow/20) % 10 == 0 ){
rgb.setColorAt(0,0,0,255);
} else {
rgb.setColorAt(0,0,0,0);
}
if( ((toneRightNow/15)) % 7 == 0 ){
rgb.setColorAt(1,0,0,255);
} else {
rgb.setColorAt(1,0,0,0);
}
rgb.show();
if( sequence > 8 ){
sequence = 0;
} else if( sequence > 4 ){
tempo = 40;
} else {
tempo = 150;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment