Created
April 3, 2018 14:45
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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