Schematic: Team 4.1’s U-box

The schematic for Team 4.1’s U-Box seems complicated but is actually fairly straightforward. There is essentially a circuit for the LED and LCD screen, and a second circuit for the servo motor. From the A3BU, 3.3V runs through a 330 Ohm resistor to a red LED and back to ground. A switch completes the loop so that the LED will only light up when the switch is flipped. The other side of the switch runs back to an input pin on the A3BU that just lets the micro-controller know which position the switch is in. This is necessary so that our LCD screen knows when to show the different faces.

Unfortunately, the 3.3V from the A3BU were not enough to power the 5V servo, so a second part of the schematic is designed to run this servo. When the switch is flipped, the A3BU tells an Arduino to run its code, and the Arduino outputs the 5V necessary to turn the servo 35 degrees. The servo will rotate and hit the switch back into the off position, causing the LED to turn back off.

Arduino code for team 4.1’s U-box

Team 4.1 Arduino controled armSince our 5v servo motor needed more juice to run than our A3BU could provide we opted to use an Arduino to power the motor for the arm. Below is the fairly simple code needed to flip the switch on our U-box. An initial position is set, then once the pin state is read high the arm position is moved to flip the switch and then return to its initial position.

#include <Servo.h>

Servo myservo;  // create servo object to control a servo

// twelve servo objects can be created on most boards

const int pin = 2;

int pos = 0;    // variable to store the servo position

int state = 0;

void setup()

{

myservo.attach(9);  // attaches the servo on pin 9 to the servo object

pinMode(pin, INPUT);

}   Continue reading Arduino code for team 4.1’s U-box

Big picture: Team 4.1’s U-box

11173644_10204267139946834_797817752_n

For our final project our goal was to do something fun that would be entertaining to anyone who used our project. Thus we came up with the idea of the U-box. Our slightly more useful box does everything your typical useless box would do except it also has a cool LCD user interface thanks to the A3BU micro controller.

For those unfamiliar with what a useless box does we can explain. Basically you flip a switch, and then an arm comes out of the box and flips the switch back. This continues until either you give up or the box runs out of power. To this our group added a user interface that shows the attitude of the U-box. The first few times you flip the switch the box is disturbed. Keep flipping and the box will become angry. Finally the box will become so angry he gives up and you win. After this the “game” starts over again.

To accomplish the task of the U-box we needed to use PWM to control the servo motor and LED, input pins to determine if the switch was flipped, and additional software to tell the LCD display what to display to the user. Below is a link to download the video!

Team 4.1 U-Box video

Code Snippet for team 4.1’s U-box

Here I will explain how the code for our U-box works. In this section everyone usually says “The code was fairly simple…”. I will say, with knowledge learned prior labs it becomes significantly easier to understand what we are doing. We figured out we needed to use the Arduino to power the servo motor due to voltage issues so we then planned to use the A3BU to control the LCD user interface. The LCD logic is controlled by the ADCB channel, J2 header, ADC1 pin PB1. Similar to the temperature conversion code we used in lab 4. After initializing the board, sysclk, sleepmgr and ADC channel I used the below expressions.In the code snippet below the ASCII faces we use can be explicitly seen, as well as the progression of faces based on the input pin PB1 and a count variable. Once the switch is flipped the input signal is converted and the voltage to PB1 becomes greater than 50 and the led begins to blink with 100% duty cycle. This signal is used to activate the LCD screen.

int mcount = 0;

static void adc_handler(ADC_t *adc, uint8_t ch_mask, adc_result_t result)
{…

if ((result > 50) && (mcount < 5)){

blink = 1;

gfx_mono_draw_string(”                      “, 0, 0, &sysfont);
gfx_mono_draw_string(”                      “, 0, 8, &sysfont);
gfx_mono_draw_string(”                      “, 0, 16, &sysfont);
gfx_mono_draw_string(”                      “, 0, 24, &sysfont);

mcount = mcount + 1;

gfx_mono_draw_string(”                      “, 0, 0, &sysfont);
gfx_mono_draw_string(”      (-)   (-)      “, 0, 8, &sysfont);
gfx_mono_draw_string(”    ________     “, 0, 16, &sysfont);
gfx_mono_draw_string(”                        “, 0, 24, &sysfont);
delay_ms(500);

gfx_mono_draw_string(”       _     _      “, 0, 0, &sysfont);
gfx_mono_draw_string(”      / \\   / \\     “, 0, 8, &sysfont);
gfx_mono_draw_string(”                       “, 0, 16, &sysfont);
gfx_mono_draw_string(”    \\_______/    “, 0, 24, &sysfont);
delay_ms(500);
}
…}