The goal of our project was to use Nintendo Switch Joycons to control a robot car and use a vision camera to detect colors, adding extra effects to the car.
Our team found a python library on GitHub that allowed the data from Joycons to be read using Python. The python code written converts the data read from the Joycons to a usable format. The program is able to read the joystick movements, button presses, and even the gyro configuration of the Joycons. The Joycons, in this case, are connected to a laptop via Bluetooth. The laptop runs the python code, which sends the converted data to an F28379D Red Board connected by a USB cable. The red board finally takes the data to calculate he speed and turn angles needed to move the robot, thus allowing the Joycons to drive the robot car.
Raspberry Pi communicates to the Red Board using RXD. The goal of this part is to manipulate the game Mario Kart. Using a webcam, Raspberry Pi is programmed to sense blobs of three colors (Red, Green, and Blue). Using Open CV, the image taken from the webcam is filtered so that only the blobs of a certain HSV range are processed. Each color will activate different functions (just as in the game Mario Kart different colored items are attributed to different special power). If red is detected, the robot car will speed up for 5 seconds by having vref (velocity control variable) to be 4. A song feature was also added when the red is detected. Therefore, the buzzer will play a certain song for the corresponding 5 seconds as the car speeds up. The activation of the buzzer is done by setting an if statement inside interrupt counter 2. A flag variable is set to zero as a global variable. Then if red is detected, the flag is set to 1. Inside counter 2, there is an if statement that plays the song if the flag is equal to 1. If green is detected, the robot car will slow down by having vref equal 1 this time. Then if blue is detected, the robot car will spin. This is done by setting turn variable to 5. The turn variable is the speed difference between the left and the right wheel of the robot car.
FinalProject.py
Pythonimport pyjoycon
import time
from Rumble import *
import serial
import struct
from serial import Serial
class MyJoyCon(
pyjoycon.GyroTrackingJoyCon,
pyjoycon.ButtonEventJoyCon,
RumbleJoyCon,
JoyCon
): pass
# initialize the serial port
ser = serial.Serial("COM8", 115200) #Open port with baud rate
joycon_id_R = get_R_id()
joycon_id_L = get_L_id()
#Give the joycons all the functionalities in the class defined above
joyconR = MyJoyCon(*joycon_id_R)
joyconL = MyJoyCon(*joycon_id_L)
#resets the orientation for the gyro mode
joyconL.reset_orientation()
joyconR.reset_orientation()
#empty matrix used for storing the last 3 button presses
Last3 = [0 for x in range(3)]
#dictionarry used for changing button presses into floats
ButtonsR = {"a": 1, "b": 2, "y": 3, "x": 4, "r":5, "zr":6, "right_sl":7, "right_sr":8 , "plus":9}
ButtonsL = {"right": 1, "down": 2, "left": 3, "up": 4, "l":5, "zl":6, "left_sl":7, "left_sr":8, "minus":9 }
global stop
#records the last three button presses
def Last_3(new_press):
Last3[2] = Last3[1]
Last3[1] = Last3[0]
Last3[0] = new_press
print(Last3)
#will vibrate the joycons. Intensity depends on freq and amp values
def Rumble(freq, amp):
data2 = RumbleData(freq/2, freq, amp)
data1 = RumbleData(freq/2, freq, amp)
b = data2.GetData()
a = data1.GetData()
joyconL._send_rumble(b)
joyconR._send_rumble(a)
#sends data of joycons gyros
def Gyromode():
stop = 0
print("Gyro Mode")
while True:
#if button "zr" is presssed 3 times, gyro mode will end
if Last3 == ['zr', 'zr', 'zr']:
break
#looks at the buttton presses of the right joycon
for event_type, status in joyconR.events():
if status == 1:
#saves the last 3 button presses
Last_3(event_type)
if event_type == "plus" and status == 1:
#if "plus" is pressed, the oreinttion will reset
joyconR.reset_orientation()
joyconL.reset_orientation()
print("reset")
if event_type == "b" and status == 1:
#rumbles when b button is pressed
Rumble(250,25)
if event_type == "r" and status == 1:
#if "r" button is pressed, send a float to tell the robot to stop moving
stop = 1
else:
stop = 0
#looks at the buttton presses of the left joycon
for event_type, status in joyconL.events():
if status == 1:
Last_3(event_type)
if event_type == "l" and status == 1:
#stop the robot if "l" is pressed
stop = 1
else:
stop = 0
'''
2) Send "##" as header, then follow by 10 floats to F28
'''
#reads the rotation and direction values from the joycons, while converting them to floats
RR0, RR1, RR2 = float(joyconR.rotation[0]), float(joyconR.rotation[1]), float(joyconR.rotation[2])
RD0, RD1, RD2 = float(joyconR.direction[0]), float(joyconR.direction[1]), float(joyconR.direction[2])
LR0, LR1, LR2 = float(joyconL.rotation[0]), float(joyconL.rotation[1]), float(joyconL.rotation[2])
LD0, LD1, LD2 = float(joyconL.direction[0]), float(joyconL.direction[1]), float(joyconL.direction[2])
ser.write(str.encode('*'))
ser.write(str.encode('#'))
#sends the data to the redboard
ser.write(struct.pack('fffffffffffff', RR0, RR1, RR2, RD0, RD1, RD2, LR0, LR1, LR2, LD0, LD1, LD2, stop))
print("joycon rotation L: ", joyconL.rotation, "joycon rotation R: ", joyconR.rotation, )
print(stop)
print()
time.sleep(.1)
#recieves and sends the joystick data from teh joycons
def Joystickmode():
stop = 0
print("Joystick Mode")
while True:
for event_type, status in joyconR.events():
if status == 1:
Last_3(event_type)
if event_type == "b" and status == 1:
#rumbes when "b" is pressed
Rumble(250,25)
if event_type == "r" and status == 1:
#stops the car when r is pressed
stop = 1
else:
stop = 0
for event_type, status in joyconL.events():
if status == 1:
Last_3(event_type)
if event_type == "l" and status == 1:
stop = 1
else:
stop = 0
#reads joytick values
joystick_LH = joyconL.get_stick_left_horizontal()
#ranges from 560 to 3405. default 1887
joystick_LV = joyconL.get_stick_left_vertical()
#ranges from 885 to 3460. default 2270
joystick_RV = joyconR.get_stick_right_vertical()
#ranges from 650 to 3350. default 1840
joystick_RH = joyconR.get_stick_right_horizontal()
#ranges from 650 to 3070. default 2160
#scales the joystick values to range from -10 to 10
LH_scaled = (joystick_LH-1887)*10/1520
LV_scaled = (joystick_LV-2270)*10/1190
RH_scaled = (joystick_RH-2160)*10/1510
RV_scaled = (joystick_RV-1840)*10/1245
#sends the scaled joystick values to the redboard
ser.write(str.encode('*'))
ser.write(str.encode('&'))
ser.write(struct.pack('fffff',LH_scaled, LV_scaled, RH_scaled, RV_scaled, stop))
print(f"RightH: {RH_scaled:.2f}, RightV: {RV_scaled:.2f}, LeftH: {LH_scaled:.2f}, LeftV: {LV_scaled:.2f}")
#if zr is pressed 3 times, leave joystick mode
if Last3 == ['zr', 'zr', 'zr']:
break
time.sleep(.1)
#reads and sends button presses
def Buttonmode():
print("Button Mode")
while True:
if Last3 == ['zr', 'zr', 'zr']:
break
for event_type, status in joyconR.events():
if status == 1:
Last_3(event_type)
ser.write(str.encode('*'))
ser.write(str.encode('@'))
#uses the dictionary defined at the top to send button presses as floats
ser.write(struct.pack('ff',ButtonsR[event_type], status))
if event_type == "b" and status == 1:
Rumble(250,25)
for event_type, status in joyconL.events():
ser.write(str.encode('*'))
ser.write(str.encode('^'))
ser.write(struct.pack('ff',ButtonsL[event_type], status))
if status == 1:
Last_3(event_type)
while True:
#changes the "mode" of the car depending on the button pressed.
for event_type, status in joyconR.events():
if status == 1:
Last_3(event_type)
if event_type == "x" and status == 1:
Gyromode()
print("Left Gyro Mode")
if event_type == "y" and status == 1:
Joystickmode()
print("Left Joystick Mode")
if event_type == "a" and status == 1:
Buttonmode()
print("Left Button Mode")
final_project.c
C/C++No preview (download only).
/* SERIAL.C: This code is designed to act as a low-level serial driver for
higher-level programming. Ideally, one could simply call init_serial()
to initialize the serial port, then use serial_send("data", 4) to send
an array of data (8-bit unsigned character strings).
WRITTEN BY : Paul Miller <pamiller@uiuc.edu>
$Id: serial.c,v 1.4 2003/08/08 16:08:56 paul Exp $
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#include "F28x_Project.h" // Device Headerfile and Examples Include File
#include <buffer.h>
#include <F28379dSerial.h>
#include <F2837xD_sci.h>
serialSCIA_t SerialA;
serialSCIB_t SerialB;
serialSCIC_t SerialC;
serialSCID_t SerialD;
char RXAdata = 0;
char RXBdata = 0;
char RXCdata = 0;
char RXDdata = 0;
uint32_t numRXA = 0;
uint32_t numRXB = 0;
uint32_t numRXC = 0;
uint32_t numRXD = 0;
float blob_color = 0;
//float cy = 0;
//float csize = 0;
float Rpointer_0;
float Rpointer_1;
float Rrotation_0;
float Rrotation_1;
float Rrotation_2;
float Rdirection_0;
float Rdirection_1;
float Rdirection_2;
float Lpointer_0;
float Lpointer_1;
float Lrotation_0;
float Lrotation_1;
float Lrotation_2;
float Ldirection_0;
float Ldirection_1;
float Ldirection_2;
float joystick_LH = 0;
float joystick_LV = 0;
float joystick_RH = 0;
float joystick_RV = 0;
float event_typeR = 0;
float statusR = 0;
float event_typeL = 0;
float statusL = 0;
float stop = 0;
uint16_t color = 0;
float mode = 0;
extern float turn;
extern float Vref;
//for serial com with pi
typedef union {
uint16_t parts[2];
float value;
} float_int;
uint16_t com_stateA = 0;
uint16_t com_stateD = 0;
char send_sci[40]; //send the float
float_int to_send[10];
uint16_t received_count = 0;
uint16_t opti_count = 0;
float_int received_pi[20];
char temp_MSB = 0;
// for SerialA
uint16_t init_serialSCIA(serialSCIA_t *s, uint32_t baud)
{
volatile struct SCI_REGS *sci;
uint32_t clk;
if (s == &SerialA) {
sci = &SciaRegs;
s->sci = sci;
init_bufferSCIA(&s->TX);
GPIO_SetupPinMux(43, GPIO_MUX_CPU1, 15);
GPIO_SetupPinOptions(43, GPIO_INPUT, GPIO_PULLUP);
GPIO_SetupPinMux(42, GPIO_MUX_CPU1, 15);
GPIO_SetupPinOptions(42, GPIO_OUTPUT, GPIO_PUSHPULL);
} else {
return 1;
}
/* init for standard baud,8N1 comm */
sci->SCICTL1.bit.SWRESET = 0; // init SCI state machines and opt flags
sci->SCICCR.all = 0x0;
sci->SCICTL1.all = 0x0;
sci->SCICTL2.all = 0x0;
sci->SCIPRI.all = 0x0;
clk = LSPCLK_HZ; // set baud rate
clk /= baud*8;
clk--;
sci->SCILBAUD.all = clk & 0xFF;
sci->SCIHBAUD.all = (clk >> 8) & 0xFF;
sci->SCICCR.bit.SCICHAR = 0x7; // (8) 8 bits per character
sci->SCICCR.bit.PARITYENA = 0; // (N) disable party calculation
sci->SCICCR.bit.STOPBITS = 0; // (1) transmit 1 stop bit
sci->SCICCR.bit.LOOPBKENA = 0; // disable loopback test
sci->SCICCR.bit.ADDRIDLE_MODE = 0; // idle-line mode (non-multiprocessor SCI comm)
sci->SCIFFCT.bit.FFTXDLY = 0; // TX: zero-delay
sci->SCIFFTX.bit.SCIFFENA = 1; // enable SCI fifo enhancements
sci->SCIFFTX.bit.TXFIFORESET = 0;
sci->SCIFFTX.bit.TXFFIL = 0x0;// TX: fifo interrupt at all levels ???? is this correct
sci->SCIFFTX.bit.TXFFINTCLR = 1; // TX: clear interrupt flag
sci->SCIFFTX.bit.TXFFIENA = 0; // TX: disable fifo interrupt
sci->SCIFFTX.bit.TXFIFORESET = 1;
sci->SCIFFRX.bit.RXFIFORESET = 0; // RX: fifo reset
sci->SCIFFRX.bit.RXFFINTCLR = 1; // RX: clear interrupt flag
sci->SCIFFRX.bit.RXFFIENA = 1; // RX: enable fifo interrupt
sci->SCIFFRX.bit.RXFFIL = 0x1; // RX: fifo interrupt
sci->SCIFFRX.bit.RXFIFORESET = 1; // RX: re-enable fifo
sci->SCICTL2.bit.RXBKINTENA = 0; // disable receiver/error interrupt
sci->SCICTL2.bit.TXINTENA = 0; // disable transmitter interrupt
sci->SCICTL1.bit.TXWAKE = 0;
sci->SCICTL1.bit.SLEEP = 0; // disable sleep mode
sci->SCICTL1.bit.RXENA = 1; // enable SCI receiver
sci->SCICTL1.bit.RXERRINTENA = 0; // disable receive error interrupt
sci->SCICTL1.bit.TXENA = 1; // enable SCI transmitter
sci->SCICTL1.bit.SWRESET = 1; // re-enable SCI
/* enable PIE interrupts */
if (s == &SerialA) {
PieCtrlRegs.PIEIER9.bit.INTx1 = 1;
PieCtrlRegs.PIEIER9.bit.INTx2 = 1;
IER |= (M_INT9);
PieCtrlRegs.PIEACK.all = (PIEACK_GROUP9);
}
return 0;
}
void uninit_serialSCIA(serialSCIA_t *s)
{
volatile struct SCI_REGS *sci = s->sci;
/* disable PIE interrupts */
if (s == &SerialA) {
PieCtrlRegs.PIEIER9.bit.INTx1 = 0;
PieCtrlRegs.PIEIER9.bit.INTx2 = 0;
IER &= ~M_INT9;
}
sci->SCICTL1.bit.RXERRINTENA = 0; // disable receive error interrupt
sci->SCICTL2.bit.RXBKINTENA = 0; // disable receiver/error interrupt
sci->SCICTL2.bit.TXINTENA = 0; // disable transmitter interrupt
sci->SCICTL1.bit.RXENA = 0; // disable SCI receiver
sci->SCICTL1.bit.TXENA = 0; // disable SCI transmitter
}
/***************************************************************************
* SERIAL_SEND()
*
* "User level" function to send data via serial. Return value is the
* length of data successfully copied to the TX buffer.
***************************************************************************/
uint16_t serial_sendSCIA(serialSCIA_t *s, char *data, uint16_t len)
{
uint16_t i = 0;
if (len && s->TX.size < BUF_SIZESCIA) {
for (i = 0; i < len; i++) {
if (buf_writeSCIA_1(&s->TX, data[i] & 0x00FF) != 0) break;
}
s->sci->SCIFFTX.bit.TXFFINTCLR = 1; // TX: clear interrupt flag
s->sci->SCIFFTX.bit.TXFFIENA = 1; // TX: enable fifo interrupt
}
return i;
}
// For SerialB
uint16_t init_serialSCIB(serialSCIB_t *s, uint32_t baud)
{
volatile struct SCI_REGS *sci;
uint32_t clk;
if (s == &SerialB) {
sci = &ScibRegs;
s->sci = sci;
init_bufferSCIB(&s->TX);
GPIO_SetupPinMux(15, GPIO_MUX_CPU1, 2);
GPIO_SetupPinOptions(15, GPIO_INPUT, GPIO_PULLUP);
GPIO_SetupPinMux(14, GPIO_MUX_CPU1, 2);
GPIO_SetupPinOptions(14, GPIO_OUTPUT, GPIO_PUSHPULL);
} else {
return 1;
}
/* init for standard baud,8N1 comm */
sci->SCICTL1.bit.SWRESET = 0; // init SCI state machines and opt flags
sci->SCICCR.all = 0x0;
sci->SCICTL1.all = 0x0;
sci->SCICTL2.all = 0x0;
sci->SCIPRI.all = 0x0;
clk = LSPCLK_HZ; // set baud rate
clk /= baud*8;
clk--;
sci->SCILBAUD.all = clk & 0xFF;
sci->SCIHBAUD.all = (clk >> 8) & 0xFF;
sci->SCICCR.bit.SCICHAR = 0x7; // (8) 8 bits per character
sci->SCICCR.bit.PARITYENA = 0; // (N) disable party calculation
sci->SCICCR.bit.STOPBITS = 0; // (1) transmit 1 stop bit
sci->SCICCR.bit.LOOPBKENA = 0; // disable loopback test
sci->SCICCR.bit.ADDRIDLE_MODE = 0; // idle-line mode (non-multiprocessor SCI comm)
sci->SCIFFCT.bit.FFTXDLY = 0; // TX: zero-delay
sci->SCIFFTX.bit.SCIFFENA = 1; // enable SCI fifo enhancements
sci->SCIFFTX.bit.TXFIFORESET = 0;
sci->SCIFFTX.bit.TXFFIL = 0x0;// TX: fifo interrupt at all levels ???? is this correct
sci->SCIFFTX.bit.TXFFINTCLR = 1; // TX: clear interrupt flag
sci->SCIFFTX.bit.TXFFIENA = 0; // TX: disable fifo interrupt
sci->SCIFFTX.bit.TXFIFORESET = 1;
sci->SCIFFRX.bit.RXFIFORESET = 0; // RX: fifo reset
sci->SCIFFRX.bit.RXFFINTCLR = 1; // RX: clear interrupt flag
sci->SCIFFRX.bit.RXFFIENA = 1; // RX: enable fifo interrupt
sci->SCIFFRX.bit.RXFFIL = 0x1; // RX: fifo interrupt
sci->SCIFFRX.bit.RXFIFORESET = 1; // RX: re-enable fifo
sci->SCICTL2.bit.RXBKINTENA = 0; // disable receiver/error interrupt
sci->SCICTL2.bit.TXINTENA = 0; // disable transmitter interrupt
sci->SCICTL1.bit.TXWAKE = 0;
sci->SCICTL1.bit.SLEEP = 0; // disable sleep mode
sci->SCICTL1.bit.RXENA = 1; // enable SCI receiver
sci->SCICTL1.bit.RXERRINTENA = 0; // disable receive error interrupt
sci->SCICTL1.bit.TXENA = 1; // enable SCI transmitter
sci->SCICTL1.bit.SWRESET = 1; // re-enable SCI
/* enable PIE interrupts */
if (s == &SerialB) {
PieCtrlRegs.PIEIER9.bit.INTx3 = 1;
PieCtrlRegs.PIEIER9.bit.INTx4 = 1;
IER |= (M_INT9);
PieCtrlRegs.PIEACK.all = (PIEACK_GROUP9);
}
return 0;
}
void uninit_serialSCIB(serialSCIB_t *s)
{
volatile struct SCI_REGS *sci = s->sci;
/* disable PIE interrupts */
if (s == &SerialB) {
PieCtrlRegs.PIEIER9.bit.INTx3 = 0;
PieCtrlRegs.PIEIER9.bit.INTx4 = 0;
IER &= ~M_INT9;
}
sci->SCICTL1.bit.RXERRINTENA = 0; // disable receive error interrupt
sci->SCICTL2.bit.RXBKINTENA = 0; // disable receiver/error interrupt
sci->SCICTL2.bit.TXINTENA = 0; // disable transmitter interrupt
sci->SCICTL1.bit.RXENA = 0; // disable SCI receiver
sci->SCICTL1.bit.TXENA = 0; // disable SCI transmitter
}
/***************************************************************************
* SERIAL_SEND()
*
* "User level" function to send data via serial. Return value is the
* length of data successfully copied to the TX buffer.
***************************************************************************/
uint16_t serial_sendSCIB(serialSCIB_t *s, char *data, uint16_t len)
{
uint16_t i = 0;
if (len && s->TX.size < BUF_SIZESCIB) {
for (i = 0; i < len; i++) {
if (buf_writeSCIB_1(&s->TX, data[i] & 0x00FF) != 0) break;
}
s->sci->SCIFFTX.bit.TXFFINTCLR = 1; // TX: clear interrupt flag
s->sci->SCIFFTX.bit.TXFFIENA = 1; // TX: enable fifo interrupt
}
return i;
}
// for SerialC
uint16_t init_serialSCIC(serialSCIC_t *s, uint32_t baud)
{
volatile struct SCI_REGS *sci;
uint32_t clk;
if (s == &SerialC) {
sci = &ScicRegs;
s->sci = sci;
init_bufferSCIC(&s->TX);
GPIO_SetupPinMux(139, GPIO_MUX_CPU1, 6);
GPIO_SetupPinOptions(139, GPIO_INPUT, GPIO_PULLUP);
GPIO_SetupPinMux(56, GPIO_MUX_CPU1, 6);
GPIO_SetupPinOptions(56, GPIO_OUTPUT, GPIO_PUSHPULL);
} else {
return 1;
}
/* init for standard baud,8N1 comm */
sci->SCICTL1.bit.SWRESET = 0; // init SCI state machines and opt flags
sci->SCICCR.all = 0x0;
sci->SCICTL1.all = 0x0;
sci->SCICTL2.all = 0x0;
sci->SCIPRI.all = 0x0;
clk = LSPCLK_HZ; // set baud rate
clk /= baud*8;
clk--;
sci->SCILBAUD.all = clk & 0xFF;
sci->SCIHBAUD.all = (clk >> 8) & 0xFF;
sci->SCICCR.bit.SCICHAR = 0x7; // (8) 8 bits per character
sci->SCICCR.bit.PARITYENA = 0; // (N) disable party calculation
sci->SCICCR.bit.STOPBITS = 0; // (1) transmit 1 stop bit
sci->SCICCR.bit.LOOPBKENA = 0; // disable loopback test
sci->SCICCR.bit.ADDRIDLE_MODE = 0; // idle-line mode (non-multiprocessor SCI comm)
sci->SCIFFCT.bit.FFTXDLY = 0; // TX: zero-delay
sci->SCIFFTX.bit.SCIFFENA = 1; // enable SCI fifo enhancements
sci->SCIFFTX.bit.TXFIFORESET = 0;
sci->SCIFFTX.bit.TXFFIL = 0x0;// TX: fifo interrupt at all levels ???? is this correct
sci->SCIFFTX.bit.TXFFINTCLR = 1; // TX: clear interrupt flag
sci->SCIFFTX.bit.TXFFIENA = 0; // TX: disable fifo interrupt
sci->SCIFFTX.bit.TXFIFORESET = 1;
sci->SCIFFRX.bit.RXFIFORESET = 0; // RX: fifo reset
sci->SCIFFRX.bit.RXFFINTCLR = 1; // RX: clear interrupt flag
sci->SCIFFRX.bit.RXFFIENA = 1; // RX: enable fifo interrupt
sci->SCIFFRX.bit.RXFFIL = 0x1; // RX: fifo interrupt
sci->SCIFFRX.bit.RXFIFORESET = 1; // RX: re-enable fifo
sci->SCICTL2.bit.RXBKINTENA = 0; // disable receiver/error interrupt
sci->SCICTL2.bit.TXINTENA = 0; // disable transmitter interrupt
sci->SCICTL1.bit.TXWAKE = 0;
sci->SCICTL1.bit.SLEEP = 0; // disable sleep mode
sci->SCICTL1.bit.RXENA = 1; // enable SCI receiver
sci->SCICTL1.bit.RXERRINTENA = 0; // disable receive error interrupt
sci->SCICTL1.bit.TXENA = 1; // enable SCI transmitter
sci->SCICTL1.bit.SWRESET = 1; // re-enable SCI
/* enable PIE interrupts */
if (s == &SerialC) {
PieCtrlRegs.PIEIER8.bit.INTx5 = 1;
PieCtrlRegs.PIEIER8.bit.INTx6 = 1;
PieCtrlRegs.PIEACK.all = (PIEACK_GROUP8);
IER |= (M_INT8);
}
return 0;
}
void uninit_serialSCIC(serialSCIC_t *s)
{
volatile struct SCI_REGS *sci = s->sci;
/* disable PIE interrupts */
if (s == &SerialC) {
PieCtrlRegs.PIEIER8.bit.INTx5 = 0;
PieCtrlRegs.PIEIER8.bit.INTx6 = 0;
IER &= ~M_INT8;
}
sci->SCICTL1.bit.RXERRINTENA = 0; // disable receive error interrupt
sci->SCICTL2.bit.RXBKINTENA = 0; // disable receiver/error interrupt
sci->SCICTL2.bit.TXINTENA = 0; // disable transmitter interrupt
sci->SCICTL1.bit.RXENA = 0; // disable SCI receiver
sci->SCICTL1.bit.TXENA = 0; // disable SCI transmitter
}
/***************************************************************************
* SERIAL_SEND()
*
* "User level" function to send data via serial. Return value is the
* length of data successfully copied to the TX buffer.
***************************************************************************/
uint16_t serial_sendSCIC(serialSCIC_t *s, char *data, uint16_t len)
{
uint16_t i = 0;
if (len && s->TX.size < BUF_SIZESCIC) {
for (i = 0; i < len; i++) {
if (buf_writeSCIC_1(&s->TX, data[i] & 0x00FF) != 0) break;
}
s->sci->SCIFFTX.bit.TXFFINTCLR = 1; // TX: clear interrupt flag
s->sci->SCIFFTX.bit.TXFFIENA = 1; // TX: enable fifo interrupt
}
return i;
}
// For Serial D
uint16_t init_serialSCID(serialSCID_t *s, uint32_t baud)
{
volatile struct SCI_REGS *sci;
uint32_t clk;
if (s == &SerialD) {
sci = &ScidRegs;
s->sci = sci;
init_bufferSCID(&s->TX);
GPIO_SetupPinMux(105, GPIO_MUX_CPU1, 6);
GPIO_SetupPinOptions(105, GPIO_INPUT, GPIO_PULLUP);
GPIO_SetupPinMux(104, GPIO_MUX_CPU1, 6);
GPIO_SetupPinOptions(104, GPIO_OUTPUT, GPIO_PUSHPULL);
}
else {
return 1;
}
/* init for standard baud,8N1 comm */
sci->SCICTL1.bit.SWRESET = 0; // init SCI state machines and opt flags
sci->SCICCR.all = 0x0;
sci->SCICTL1.all = 0x0;
sci->SCICTL2.all = 0x0;
sci->SCIPRI.all = 0x0;
clk = LSPCLK_HZ; // set baud rate
clk /= baud*8;
clk--;
sci->SCILBAUD.all = clk & 0xFF;
sci->SCIHBAUD.all = (clk >> 8) & 0xFF;
sci->SCICCR.bit.SCICHAR = 0x7; // (8) 8 bits per character
sci->SCICCR.bit.PARITYENA = 0; // (N) disable party calculation
sci->SCICCR.bit.STOPBITS = 0; // (1) transmit 1 stop bit
sci->SCICCR.bit.LOOPBKENA = 0; // disable loopback test
sci->SCICCR.bit.ADDRIDLE_MODE = 0; // idle-line mode (non-multiprocessor SCI comm)
sci->SCIFFCT.bit.FFTXDLY = 0; // TX: zero-delay
sci->SCIFFTX.bit.SCIFFENA = 1; // enable SCI fifo enhancements
sci->SCIFFTX.bit.TXFIFORESET = 0;
sci->SCIFFTX.bit.TXFFIL = 0x0;// TX: fifo interrupt at all levels ???? is this correct
sci->SCIFFTX.bit.TXFFINTCLR = 1; // TX: clear interrupt flag
sci->SCIFFTX.bit.TXFFIENA = 0; // TX: disable fifo interrupt
sci->SCIFFTX.bit.TXFIFORESET = 1;
sci->SCIFFRX.bit.RXFIFORESET = 0; // RX: fifo reset
sci->SCIFFRX.bit.RXFFINTCLR = 1; // RX: clear interrupt flag
sci->SCIFFRX.bit.RXFFIENA = 1; // RX: enable fifo interrupt
sci->SCIFFRX.bit.RXFFIL = 0x1; // RX: fifo interrupt
sci->SCIFFRX.bit.RXFIFORESET = 1; // RX: re-enable fifo
sci->SCICTL2.bit.RXBKINTENA = 0; // disable receiver/error interrupt
sci->SCICTL2.bit.TXINTENA = 0; // disable transmitter interrupt
sci->SCICTL1.bit.TXWAKE = 0;
sci->SCICTL1.bit.SLEEP = 0; // disable sleep mode
sci->SCICTL1.bit.RXENA = 1; // enable SCI receiver
sci->SCICTL1.bit.RXERRINTENA = 0; // disable receive error interrupt
sci->SCICTL1.bit.TXENA = 1; // enable SCI transmitter
sci->SCICTL1.bit.SWRESET = 1; // re-enable SCI
/* enable PIE interrupts */
if (s == &SerialD) {
PieCtrlRegs.PIEIER8.bit.INTx7 = 1;
PieCtrlRegs.PIEIER8.bit.INTx8 = 1;
PieCtrlRegs.PIEACK.all = (PIEACK_GROUP8);
IER |= (M_INT8);
}
return 0;
}
void uninit_serialSCID(serialSCID_t *s)
{
volatile struct SCI_REGS *sci = s->sci;
/* disable PIE interrupts */
if (s == &SerialD) {
PieCtrlRegs.PIEIER8.bit.INTx7 = 0;
PieCtrlRegs.PIEIER8.bit.INTx8 = 0;
IER &= ~M_INT8;
}
sci->SCICTL1.bit.RXERRINTENA = 0; // disable receive error interrupt
sci->SCICTL2.bit.RXBKINTENA = 0; // disable receiver/error interrupt
sci->SCICTL2.bit.TXINTENA = 0; // disable transmitter interrupt
sci->SCICTL1.bit.RXENA = 0; // disable SCI receiver
sci->SCICTL1.bit.TXENA = 0; // disable SCI transmitter
}
/***************************************************************************
* SERIAL_SEND()
*
* "User level" function to send data via serial. Return value is the
* length of data successfully copied to the TX buffer.
***************************************************************************/
uint16_t serial_sendSCID(serialSCID_t *s, char *data, uint16_t len)
{
uint16_t i = 0;
if (len && s->TX.size < BUF_SIZESCID) {
for (i = 0; i < len; i++) {
if (buf_writeSCID_1(&s->TX, data[i] & 0x00FF) != 0) break;
}
s->sci->SCIFFTX.bit.TXFFINTCLR = 1; // TX: clear interrupt flag
s->sci->SCIFFTX.bit.TXFFIENA = 1; // TX: enable fifo interrupt
}
return i;
}
/***************************************************************************
* TXxINT_DATA_SENT()
*
* Executed when transmission is ready for additional data. These functions
* read the next char of data and put it in the TXBUF register for transfer.
***************************************************************************/
#ifdef _FLASH
#pragma CODE_SECTION(TXAINT_data_sent, ".TI.ramfunc");
#endif
__interrupt void TXAINT_data_sent(void)
{
char data;
if (buf_readSCIA_1(&SerialA.TX,0,&data) == 0) {
while ( (buf_readSCIA_1(&SerialA.TX,0,&data) == 0)
&& (SerialA.sci->SCIFFTX.bit.TXFFST != 0x10) ) {
buf_removeSCIA(&SerialA.TX, 1);
SerialA.sci->SCITXBUF.all = data;
}
} else {
SerialA.sci->SCIFFTX.bit.TXFFIENA = 0; // TX: disable fifo interrupt
}
SerialA.sci->SCIFFTX.bit.TXFFINTCLR = 1; // TX: clear interrupt flag
PieCtrlRegs.PIEACK.all = PIEACK_GROUP9;
}
//for serialB
#ifdef _FLASH
#pragma CODE_SECTION(TXBINT_data_sent, ".TI.ramfunc");
#endif
__interrupt void TXBINT_data_sent(void)
{
char data;
if (buf_readSCIB_1(&SerialB.TX,0,&data) == 0) {
while ( (buf_readSCIB_1(&SerialB.TX,0,&data) == 0)
&& (SerialB.sci->SCIFFTX.bit.TXFFST != 0x10) ) {
buf_removeSCIB(&SerialB.TX, 1);
SerialB.sci->SCITXBUF.all = data;
}
} else {
SerialB.sci->SCIFFTX.bit.TXFFIENA = 0; // TX: disable fifo interrupt
}
SerialB.sci->SCIFFTX.bit.TXFFINTCLR = 1; // TX: clear interrupt flag
PieCtrlRegs.PIEACK.all = PIEACK_GROUP9;
}
//for serialC
#ifdef _FLASH
#pragma CODE_SECTION(TXCINT_data_sent, ".TI.ramfunc");
#endif
__interrupt void TXCINT_data_sent(void)
{
char data;
if (buf_readSCIC_1(&SerialC.TX,0,&data) == 0) {
while ( (buf_readSCIC_1(&SerialC.TX,0,&data) == 0)
&& (SerialC.sci->SCIFFTX.bit.TXFFST != 0x10) ) {
buf_removeSCIC(&SerialC.TX, 1);
SerialC.sci->SCITXBUF.all = data;
}
} else {
SerialC.sci->SCIFFTX.bit.TXFFIENA = 0; // TX: disable fifo interrupt
}
SerialC.sci->SCIFFTX.bit.TXFFINTCLR = 1; // TX: clear interrupt flag
PieCtrlRegs.PIEACK.all = PIEACK_GROUP8;
}
//for serialD
#ifdef _FLASH
#pragma CODE_SECTION(TXDINT_data_sent, ".TI.ramfunc");
#endif
__interrupt void TXDINT_data_sent(void)
{
char data;
if (buf_readSCID_1(&SerialD.TX,0,&data) == 0) {
while ( (buf_readSCID_1(&SerialD.TX,0,&data) == 0)
&& (SerialD.sci->SCIFFTX.bit.TXFFST != 0x10) ) {
buf_removeSCID(&SerialD.TX, 1);
SerialD.sci->SCITXBUF.all = data;
}
} else {
SerialD.sci->SCIFFTX.bit.TXFFIENA = 0; // TX: disable fifo interrupt
}
SerialD.sci->SCIFFTX.bit.TXFFINTCLR = 1; // TX: clear interrupt flag
PieCtrlRegs.PIEACK.all = PIEACK_GROUP8;
}
//for SerialA
#ifdef _FLASH
#pragma CODE_SECTION(RXAINT_recv_ready, ".TI.ramfunc");
#endif
//recieves and sends data to laptop
__interrupt void RXAINT_recv_ready(void)
{
RXAdata = SciaRegs.SCIRXBUF.all;
/* SCI PE or FE error */
if (RXAdata & 0xC000) {
SciaRegs.SCICTL1.bit.SWRESET = 0;
SciaRegs.SCICTL1.bit.SWRESET = 1;
SciaRegs.SCIFFRX.bit.RXFIFORESET = 0;
SciaRegs.SCIFFRX.bit.RXFIFORESET = 1;
} else {
RXAdata = RXAdata & 0x00FF;
numRXA ++;
if (com_stateA == 0) { //wait for data from pi
Rpointer_0=0;
Rpointer_1=0;
Rrotation_0=0;
Rrotation_1=0;
Rrotation_2=0;
Rdirection_0=0;
Rdirection_1=0;
Rdirection_2=0;
Lpointer_0=0;
Lpointer_1=0;
Lrotation_0=0;
Lrotation_1=0;
Lrotation_2=0;
Ldirection_0=0;
Ldirection_1=0;
Ldirection_2=0;
joystick_LH = 0;
joystick_LV = 0;
joystick_RH = 0;
joystick_RV = 0;
event_typeR = 0;
statusR = 0;
event_typeL = 0;
statusL = 0;
stop = 0;
if (RXAdata == '*'){
com_stateA = 1;//pre echo state
} else if (RXAdata == '!'){
com_stateA = 2;//pre sending state
} else {
com_stateA = 0;
}
} else if (com_stateA == 1) {
if(RXAdata == '&') {
com_stateA = 9; //activate joystick mode
} else if(RXAdata == '#') {
com_stateA = 8; //activate gyro mode
} else if(RXAdata == '@') {
com_stateA = 7; //activate button mode right joycon
} else if(RXAdata == '^') {
com_stateA = 6; //activate buttonmode for the left joycon
} else {
com_stateA = 0;
}
} else if (com_stateA == 9) { //send in joystick mode
if (received_count % 2 == 0) {
temp_MSB = RXAdata;
} else {
received_pi[received_count/4].parts[(received_count%4)/2] = ((RXAdata << 8) | temp_MSB) & 0xFFFF;
}
received_count += 1;
if (received_count == 20){ //4 x number vals
com_stateA = 0;
received_count = 0;
joystick_LH = received_pi[0].value;
joystick_LV = received_pi[1].value;
joystick_RH = received_pi[2].value;
joystick_RV = received_pi[3].value;
stop = received_pi[4].value;
}
} else if (com_stateA == 8) { //send in gyro mode
if (received_count % 2 == 0) {
temp_MSB = RXAdata;
} else {
received_pi[received_count/4].parts[(received_count%4)/2] = ((RXAdata << 8) | temp_MSB) & 0xFFFF;
}
received_count += 1;
if (received_count == 52){ //4 x number vals
com_stateA = 0;
received_count = 0;
Rrotation_0 = received_pi[0].value;
Rrotation_1 = received_pi[1].value;
Rrotation_2 = received_pi[2].value;
Rdirection_0 = received_pi[3].value;
Rdirection_1 = received_pi[4].value;
Rdirection_2 = received_pi[5].value;
Lrotation_0 = received_pi[6].value;
Lrotation_1 = received_pi[7].value;
Lrotation_2 = received_pi[8].value;
Ldirection_0 = received_pi[9].value;
Ldirection_1 = received_pi[10].value;
Ldirection_2 = received_pi[11].value;
stop = received_pi[12].value;
}
} else if (com_stateA == 7) { //e\\button mode right joycon
if (received_count % 2 == 0) {
temp_MSB = RXAdata;
} else {
received_pi[received_count/4].parts[(received_count%4)/2] = ((RXAdata << 8) | temp_MSB) & 0xFFFF;
}
received_count += 1;
if (received_count == 8){ //4 x number vals
com_stateA = 0;
received_count = 0;
event_typeR = received_pi[0].value;
statusR = received_pi[1].value;
}
} else if (com_stateA == 6) { //button mode left joycon
if (received_count % 2 == 0) {
temp_MSB = RXAdata;
} else {
received_pi[received_count/4].parts[(received_count%4)/2] = ((RXAdata << 8) | temp_MSB) & 0xFFFF;
}
received_count += 1;
if (received_count == 8){ //4 x number vals
com_stateA = 0;
received_count = 0;
event_typeL = received_pi[0].value;
statusL = received_pi[1].value;
}
} else if (com_stateA == 2) {
if (RXAdata == '!') {
int i = 0;
for (i = 0; i < 10; i++) {
to_send[i].value = 10*i;
}
for (i = 0; i < 10; i++) {
send_sci[4*i] = to_send[i].parts[0] & 0xFF;
send_sci[4*i+1] = (to_send[i].parts[0]>>8) & 0xFF;
send_sci[4*i+2] = to_send[i].parts[1] & 0xFF;
send_sci[4*i+3] = (to_send[i].parts[1]>>8) & 0xFF;
}
serial_sendSCIA(&SerialA, send_sci, 40);
com_stateA = 0;
} else {
com_stateA = 0;
}
}
}
SciaRegs.SCIFFRX.bit.RXFFINTCLR = 1;
ScidRegs.SCIFFRX.bit.RXFFOVRCLR = 1;
PieCtrlRegs.PIEACK.all = PIEACK_GROUP9;
}
//for SerialB
#ifdef _FLASH
#pragma CODE_SECTION(RXBINT_recv_ready, ".TI.ramfunc");
#endif
__interrupt void RXBINT_recv_ready(void)
{
RXBdata = ScibRegs.SCIRXBUF.all;
/* SCI PE or FE error */
if (RXBdata & 0xC000) {
ScibRegs.SCICTL1.bit.SWRESET = 0;
ScibRegs.SCICTL1.bit.SWRESET = 1;
ScibRegs.SCIFFRX.bit.RXFIFORESET = 0;
ScibRegs.SCIFFRX.bit.RXFIFORESET = 1;
} else {
RXBdata = RXBdata & 0x00FF;
// Do something with recieved character
numRXB ++;
}
ScibRegs.SCIFFRX.bit.RXFFINTCLR = 1;
PieCtrlRegs.PIEACK.all = PIEACK_GROUP9;
}
// for SerialC
#ifdef _FLASH
#pragma CODE_SECTION(RXCINT_recv_ready, ".TI.ramfunc");
#endif
__interrupt void RXCINT_recv_ready(void)
{
RXCdata = ScicRegs.SCIRXBUF.all;
/* SCI PE or FE error */
if (RXCdata & 0xC000) {
ScicRegs.SCICTL1.bit.SWRESET = 0;
ScicRegs.SCICTL1.bit.SWRESET = 1;
ScicRegs.SCIFFRX.bit.RXFIFORESET = 0;
ScicRegs.SCIFFRX.bit.RXFIFORESET = 1;
} else {
RXCdata = RXCdata & 0x00FF;
numRXC ++;
}
ScicRegs.SCIFFRX.bit.RXFFINTCLR = 1;
ScicRegs.SCIFFRX.bit.RXFFOVRCLR = 1;
PieCtrlRegs.PIEACK.all = PIEACK_GROUP8;
}
char temp1[100];
//for SerialD
#ifdef _FLASH
#pragma CODE_SECTION(RXDINT_recv_ready, ".TI.ramfunc");
#endif
__interrupt void RXDINT_recv_ready(void)
{
RXDdata = ScidRegs.SCIRXBUF.all;
/* SCI PE or FE error */
if (RXDdata & 0xC000) {
ScidRegs.SCICTL1.bit.SWRESET = 0;
ScidRegs.SCICTL1.bit.SWRESET = 1;
ScidRegs.SCIFFRX.bit.RXFIFORESET = 0;
ScidRegs.SCIFFRX.bit.RXFIFORESET = 1;
} else {
RXDdata = RXDdata & 0x00FF;
temp1[numRXD%100] = RXDdata;
numRXD ++;
if (com_stateD == 0) { //wait for data from pi
color = 0;
if (RXDdata == '*'){
com_stateD = 1;//pre echo state
} else {
com_stateD = 0;
}
} else if (com_stateD == 1) {
if(RXDdata == '*') {
com_stateD = 10; //activate seeing colors
} else {
com_stateD = 0;
}
} else if (com_stateD == 10) { //echo stats
if (RXDdata == 'r'){
color = 1;
} else if (RXDdata == 'b') {
color = 3;
} else if (RXDdata == 'g') {
color = 2;
}
}
ScidRegs.SCIFFRX.bit.RXFFINTCLR = 1;
ScidRegs.SCIFFRX.bit.RXFFOVRCLR = 1;
PieCtrlRegs.PIEACK.all = PIEACK_GROUP8;
}
}
// SerialA only setup for Tera Term connection
char serial_printf_bufSCIA[BUF_SIZESCIA];
uint16_t serial_printf(serialSCIA_t *s, char *fmt, ...)
{
va_list ap;
va_start(ap,fmt);
vsprintf(serial_printf_bufSCIA,fmt,ap);
va_end(ap);
return serial_sendSCIA(s,serial_printf_bufSCIA,strlen(serial_printf_bufSCIA));
}
#!/usr/bin/env python3
import numpy as np
import cv2
import time
#for communication
import serial
import struct
from serial import Serial
#to the red board
# initialize the serial port
ser = serial.Serial("/dev/ttyAMA1", 115200) #Open port with baud rate
# Capturing video through webcam
webcam = cv2.VideoCapture(0)
# Start a while loop
while(1):
# Reading the video from the
# webcam in image frames
_, imageFrame = webcam.read()
imageFrame = cv2.resize(imageFrame, (300,300))
# Convert the imageFrame in
# BGR(RGB color space) to
# HSV(hue-saturation-value)
# color space
hsvFrame = cv2.cvtColor(imageFrame, cv2.COLOR_BGR2HSV)
# Set range for red color and
# define mask
red_lower = np.array([150, 150, 120], np.uint8)
red_upper = np.array([180, 255, 255], np.uint8)
red_mask = cv2.inRange(hsvFrame, red_lower, red_upper)
# Set range for green color and
# define mask
green_lower = np.array([60, 150, 130], np.uint8)
green_upper = np.array([90, 255, 255], np.uint8)
green_mask = cv2.inRange(hsvFrame, green_lower, green_upper)
# Set range for blue color and
# define mask
blue_lower = np.array([95, 120, 150], np.uint8)
blue_upper = np.array([140, 255, 255], np.uint8)
blue_mask = cv2.inRange(hsvFrame, blue_lower, blue_upper)
# Morphological Transform, Dilation
# for each color and bitwise_and operator
# between imageFrame and mask determines
# to detect only that particular color
kernal = np.ones((5, 5), "uint8")
# For red color
red_mask = cv2.dilate(red_mask, kernal)
res_red = cv2.bitwise_and(imageFrame, imageFrame,
mask = red_mask)
# For green color
green_mask = cv2.dilate(green_mask, kernal)
res_green = cv2.bitwise_and(imageFrame, imageFrame,
mask = green_mask)
# For blue color
blue_mask = cv2.dilate(blue_mask, kernal)
res_blue = cv2.bitwise_and(imageFrame, imageFrame,
mask = blue_mask)
# Creating contour to track red color
contours, hierarchy = cv2.findContours(red_mask,
cv2.RETR_TREE,
cv2.CHAIN_APPROX_SIMPLE)
colors = 0.0
for pic, contour in enumerate(contours):
area = cv2.contourArea(contour)
if(area > 300):
x, y, w, h = cv2.boundingRect(contour)
imageFrame = cv2.rectangle(imageFrame, (x, y),
(x + w, y + h),
(0, 0, 255), 2)
cv2.putText(imageFrame, "Red Colour", (x, y),
cv2.FONT_HERSHEY_SIMPLEX, 1.0,
(0, 0, 255))
print("red")
colors = 1.0
# write header for F28 to send 10 floats
ser.write(str.encode('*'))
ser.write(str.encode('*'))
ser.write(str.encode('r'))
# Creating contour to track green color
contours, hierarchy = cv2.findContours(green_mask,
cv2.RETR_TREE,
cv2.CHAIN_APPROX_SIMPLE)
for pic, contour in enumerate(contours):
area = cv2.contourArea(contour)
if(area > 300):
x, y, w, h = cv2.boundingRect(contour)
imageFrame = cv2.rectangle(imageFrame, (x, y),
(x + w, y + h),
(0, 255, 0), 2)
cv2.putText(imageFrame, "Green Colour", (x, y),
cv2.FONT_HERSHEY_SIMPLEX,
1.0, (0, 255, 0))
print("green")
colors = 2.0
# write header for F28 to send 10 floats
ser.write(str.encode('*'))
ser.write(str.encode('*'))
ser.write(str.encode('g'))
# Creating contour to track blue color
contours, hierarchy = cv2.findContours(blue_mask,
cv2.RETR_TREE,
cv2.CHAIN_APPROX_SIMPLE)
for pic, contour in enumerate(contours):
area = cv2.contourArea(contour)
if(area > 300):
x, y, w, h = cv2.boundingRect(contour)
imageFrame = cv2.rectangle(imageFrame, (x, y),
(x + w, y + h),
(255, 0, 0), 2)
cv2.putText(imageFrame, "Blue Colour", (x, y),
cv2.FONT_HERSHEY_SIMPLEX,
1.0, (255, 0, 0))
print("blue")
colors = 3.0
# write header for F28 to send 10 floats
ser.write(str.encode('*'))
ser.write(str.encode('*'))
ser.write(str.encode('b'))
# Program Termination
cv2.imshow("Multiple Color Detection in Real-TIme", imageFrame)
if cv2.waitKey(10) & 0xFF == ord('q'):
cap.release()
cv2.destroyAllWindows()
break
#define FUDGEFACTORNOTE 1
#define C4NOTE ((uint16_t)(((FUDGEFACTORNOTE*50000000/2)/2)/261.63))
#define D4NOTE ((uint16_t)(((FUDGEFACTORNOTE*50000000/2)/2)/293.66))
#define E4NOTE ((uint16_t)(((FUDGEFACTORNOTE*50000000/2)/2)/329.63))
#define F4NOTE ((uint16_t)(((FUDGEFACTORNOTE*50000000/2)/2)/349.23))
#define G4NOTE ((uint16_t)(((FUDGEFACTORNOTE*50000000/2)/2)/392.00))
#define A4NOTE ((uint16_t)(((FUDGEFACTORNOTE*50000000/2)/2)/440.00))
#define B4NOTE ((uint16_t)(((FUDGEFACTORNOTE*50000000/2)/2)/493.88))
#define C5NOTE ((uint16_t)(((FUDGEFACTORNOTE*50000000/2)/2)/523.25))
#define D5NOTE ((uint16_t)(((FUDGEFACTORNOTE*50000000/2)/2)/587.33))
#define E5NOTE ((uint16_t)(((FUDGEFACTORNOTE*50000000/2)/2)/659.25))
#define F5NOTE ((uint16_t)(((FUDGEFACTORNOTE*50000000/2)/2)/698.46))
#define G5NOTE ((uint16_t)(((FUDGEFACTORNOTE*50000000/2)/2)/783.99))
#define A5NOTE ((uint16_t)(((FUDGEFACTORNOTE*50000000/2)/2)/880.00))
#define B5NOTE ((uint16_t)(((FUDGEFACTORNOTE*50000000/2)/2)/987.77))
#define F4SHARPNOTE ((uint16_t)(((FUDGEFACTORNOTE*50000000/2)/2)/369.99))
#define G4SHARPNOTE ((uint16_t)(((FUDGEFACTORNOTE*50000000/2)/2)/415.3))
#define A4FLATNOTE ((uint16_t)(((FUDGEFACTORNOTE*50000000/2)/2)/415.3))
#define C5SHARPNOTE ((uint16_t)(((FUDGEFACTORNOTE*50000000/2)/2)/554.37))
#define A5FLATNOTE ((uint16_t)(((FUDGEFACTORNOTE*50000000/2)/2)/830.61))
#define C6SHARPNOTE ((uint16_t)(((FUDGEFACTORNOTE*50000000/2)/2)/1108.73))
#define D6SHARPNOTE ((uint16_t)(((FUDGEFACTORNOTE*50000000/2)/2)/1244.51))
#define C6NOTE ((uint16_t)(0.02189*1046.5))
#define OFFNOTE 1
#define SONG_LENGTH 516
#define SONG_LENGTH2 100
uint16_t starsong[40] = {
OFFNOTE,
C5NOTE,
OFFNOTE,
C5NOTE,
OFFNOTE,
C5NOTE,
OFFNOTE,
//7
D4NOTE,
C5NOTE,
OFFNOTE,
C5NOTE,
OFFNOTE,
//5
D4NOTE,
C5NOTE,
D4NOTE,
C5NOTE,
//4
OFFNOTE,
B4NOTE,
OFFNOTE,
B4NOTE,
OFFNOTE,
B4NOTE,
OFFNOTE,
//7
A4NOTE,
C4NOTE,
OFFNOTE,
B4NOTE,
OFFNOTE,
//5
B4NOTE,
C4NOTE,
B4NOTE,
C4NOTE,
//4
};
uint16_t slowsong[20] = {
OFFNOTE,
E4NOTE,
E4NOTE,
E4NOTE,
D4NOTE,
D4NOTE,
D4NOTE,
E4NOTE,
E4NOTE,
E4NOTE,
D4NO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