111763 Views
85221 Views
83639 Views
51774 Views
49949 Views
48472 Views
Obsidian - the best tool for Makers
10 Projects for your Raspberry Pi Pico
Raspberry Pi Telegraf Setup with Docker
Setting Up Dynamic DNS on a Raspberry Pi for Self-Hosting
Raspberry Pi WordPress Setup with Docker
Raspberry Pi WireGuard VPN Setup with Docker
Using the Raspberry Pi Pico's Built-in Temperature Sensor
Getting Started with SQL
Introduction to the Linux Command Line on Raspberry Pi OS
How to install MicroPython
Wall Drawing Robot Tutorial
BrachioGraph Tutorial
KevsRobots Learning Platform
70% Percent Complete
By Kevin McAleer, 3 Minutes
In this lesson you will learn how to connect a HC-08 (or HC-09 / HC-10) bluetooth module to your Arduino and then use that to pair to an iOS or Android phone. We will then modify the code written in previous lessons to remotely control our SMARS.
Before you begin, you’ll need to make sure you have a couple of things before you start this lesson:
New Sketch
You can download the code below from GitHub, but its better to type it in yourself line by line, as you will get to understand what each line means.
Make sure to download the pitches.h and melody.h, from the github link above, to the same folder where you create the code below.
pitches.h
melody.h
#include <Dabble.h> #include <SoftwareSerial.h> #include "pitches.h" #define CUSTOM_SETTINGS #define INCLUDE_GAMEPAD_MODULE // set Motor A to Arduino Pins int motor_A = 12; // official Arduino Motor Shield uses D12 int motor_B = 13; // official Arduino Motor Shield uses D13 int buzzer = 4; // set the Motor Speed using the Arduino Pins int motor_A_speed = 10; // official Arduino Motor Shield uses D3 int motor_B_speed = 11; // official Arduino Motor Shield uses D11 // set the time between motor on and motor off int wait_in_milliseconds = 100; void setup() { // put your setup code here, to run once: Dabble.begin(9600); Serial.begin(9600); // set the Arduino pin to OUTPUT mode pinMode(motor_A, OUTPUT); pinMode(motor_B, OUTPUT); pinMode(buzzer, OUTPUT); } // notes in the melody: int melody[] = { F3, D3, AS2, AS2, AS2, C3, D3, DS3, F3, F3, F3 ,D3 }; int noteDurations[] = { 8, 8, 4, 4, 8, 8, 8, 8, 4, 4, 4, 8 }; struct Note { int key; int duraiton; }; void playMelody() { for (int thisNote = 0; thisNote < 12 ; thisNote++) { // to calculate the note duration, take one second divided by the note type. //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc. int noteDuration = 1000 / noteDurations[thisNote]; tone(4, melody[thisNote], noteDuration); // to distinguish the notes, set a minimum time between them. // the note's duration + 30% seems to work well: int pauseBetweenNotes = noteDuration * 1.30; delay(pauseBetweenNotes); // stop the tone playing: noTone(8); } } void loop() { // put your main code here, to run repeatedly: Dabble.processInput(); if (GamePad.isUpPressed()) forward(); if (GamePad.isDownPressed()) backward(); if (GamePad.isLeftPressed()) turnLeft(); if (GamePad.isRightPressed()) turnRight(); if (GamePad.isTrianglePressed()) beep(); if (GamePad.isSquarePressed()) playMelody(); }
< Previous Next >