231a-ag Software Description

From CSclasswiki
Jump to: navigation, search

Software Description


I am planning on scaling down the complexity my project a bit for the final prototype. Instead of having the user set a time for the alarm to go off, it will go off at a predetermined time. This is very obviously not the intent of an alarm clock, but I feel that implementing user input at this point may be a bit difficult. If everything else plays out well and is working well ahead of time, I may try to implement the user input.

This is how the software should work --

  • There is a predetermined time at which the alarm will go off. At this time, a signal will be sent to the buzzer, which will turn on and begin buzzing (this is the alarm). Then, four LEDs in sequence will light up on the keypad. I may or may not decide to make it light up 1-3 times with a distinct delay between the same sequences, so that the user has some time to at least look at it and process it. I could also put in a delay between when the buzzer starts to buzz.
  • The Arduino will then begin to read the input on the keypad, as the buttons are pressed. The sequence of buttons will then be evaluated and compared to the correct sequence.
  • If the sequence entered is incorrect, then the buzzer will continue to buzz, and perhaps the LED sequence will flash again. Then, the user can try to enter the code again.
  • If the sequence entered is correct, then the buzzer will stop buzzing, and that's the end.

Arduino Sketch

  • setup():
    • Set up LEDs' pins as output.
    • Set up buzzer pin as output.
    • Set up pins to output/input.
  • loop():
  1. When certain time is reached, assembly will send signal to Arduino to set buzzer on.
  2. Set up a delay, and flash LED sequence.
  3. Read analog input pins. When an analog pin value is under 200, go to keyPressed() function.
  4. If sequenced entered is correct, set buzzer off.
  5. If sequence entered is incorrect, loop again to step 2.
    • keyPressed() function will take analog input pin read earlier, and set all the digital output pins to "high." In turn, set one of the three digital output pins to "low." After setting each digital output pin to "low," reread the status of the analog input pin. Once an analog input pin reads "low," then deduce which button is being pressed, and send this to the assembly program.


driver.c will have to be at least modified to get the local time:

#include <stdio.h>
#include <time.h>

extern int asm_main( void );    // entry point of assembly                      
extern time_t currentTime;       // assembly storage for time                   

int* _getLocalTime( ) {
  return (int*) localtime( &currentTime );

int main() {
  // call assembly program                                                      

The driver.c program should also implement code to produce a randomized number.

Assembly Language

  • Set up variables:
    • Four arrays containing different possible sequences to be displayed.
    • First, second, third and fourth correct numbers.
    • First, second, third and fourth user inputs.
    • Alarm hour, minute and second.
  • Get the time of day from the computer.
  • Compare hour, minute and second from time of day to the hour, minute and second that the alarm is supposed to go off.
  • Once the two match up, generate a random number. (Arduino buzzer should also go off.)
  • AND this random number with 0x00000011 (in decimal = 3), to get a number between 0 and 3.
  • Depending on whether the number between 0 and 3 is 0, 1, 2 or 3, it will correspond to a certain array with a sequence.
  • Sent this sequence to the Arduino. (Arduino will begin to loop.)
  • Read user input from Arduino.
  • Compare user input to the correct sequence.
  • Send appropriate signal to Arduino (right/wrong sequence).

The First Step

I'm making note of a "first step" implementation, that will be implemented first, and then once this works, I will begin to make the program more complicated. The following steps include both what the assembly and the Arduino programs will do.

  • Get the time of day from the computer.
  • Compare hour, minute and second from time of day to the hour, minute and second that the alarm is supposed to go off.
  • Once the two match up, the Arduino buzzer should begin to go off.
  • The sequence for the "first step" implementation will be preset to just one sequence. This sequence will then flash on the LED matrix.
  • The Arduino will read the buttons pushed on the keypad, and relay these to the assembly program.
  • The assembly program will compare the user-entered sequence with the correct sequence.
  • If the sequence is correct, then the buzzer will stop buzzing. If not, loop again.