Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: DS1302 keypad mbed
Diff: main.cpp
- Revision:
- 1:24446776f0d2
- Parent:
- 0:3ff58b093415
- Child:
- 2:aee9ee1296cd
--- a/main.cpp Sun Feb 16 00:32:06 2014 +0000
+++ b/main.cpp Wed Apr 09 02:59:16 2014 +0000
@@ -1,9 +1,14 @@
/* Introduction
Arduino DSKY
This is a personal project used developed by penguinos to mix old school technology with a modern twist.
-Version 0.01: Feb. 4 2014
- Switch platforms from Arduino to KL25Z by Freescale. Because of this, Revision number is resetted.
- Major Revision to Code are being undertaken.
+Version 0.02: March. 4 2014
+ Added Keypad Functionality
+ - Added fucntion for Verb
+ - Added function for Noun
+ - Added function for Enter
+ - Used goto in Verb and Noun to prevent any nestled Loops.
+ - Contains Button_Sort Function to move location based on button press
+ Cleaned certain parts of the code for efficentcy
Notable Credits:
NASA! - Release of technical documentations regarding the AGC and DSKY
@@ -14,13 +19,20 @@
*/
using namespace std;
#include "mbed.h"
+#include "Keypad.h" // Keypad
//Declare Variables
int shift = 0; // Shift Data
// In the Arduino Version it uses a String. Will use an Int instead to see if this works on Mbed
-int Verb;
-int Noun;
-int Enter;
+int Verb_Number1 = 0;
+int Verb_Number2 = 0;
+int Noun_Number1 = 0;
+int Noun_Number2 = 0;
+int Enter_Number1 = 0;
+int Enter_Number2 = 0;
+int Verb; // DSKY Verb
+int Noun; // DSkY Noun
+int Enter; // DSKY Enter
int Set_GET_Seconds = 30; // Configure the Set Get in seconds. 1/100th of a second
char Set_get_miliseconds = 10;
char Set_Get_Seconds_Byte = 0;
@@ -28,21 +40,47 @@
char data = 0;
char data2 = 0;
char data3 = 0;
-char nibble[10] = // Holds variables for nibbles for number 0-9 in hexes. nibble ALL the things!
- {0x00, 0x01, 0x02, 0x03, 0x04,
- 0x05, 0x06, 0x07, 0x08, 0x09};
+char nibble[10] = { // Holds variables for nibbles for number 0-9 in hexes. nibble ALL the things!
+ 0x00, 0x01, 0x02, 0x03, 0x04,
+ 0x05, 0x06, 0x07, 0x08, 0x09
+};
+
+char Keytable[] = { '1', '2', '3', '+', // R0
+ '4', '5', '6', '-', // R1
+ '7', '8', '9', 'E', // R2
+ 'V', '0', 'N', 'R', // R3
+ };
+// C0 C1 C2 C3
+
+int32_t Index = -1; // Button
+int State;
// Function Declaration
+void Verb_Button();
+void Noun_Button();
+void Enter_Button();
+void compare();
+void Button_Sort(int sort); // Function that sorts Verb Values
void blinkAll(int amount, int delay);// Function that Blinks all LED
//void ShiftingOut(char myDataOut);
+// Program Name
+void Ground_Elapse_Time(); // Ground Elapse Time
+
// Pin modes for each pins
-DigitalOut LatchPin(PTD4); //Pin for ST_CP of 74HC595 Pin # 12
-DigitalOut ClockPin(PTA12); //Pin for SH_CP of 74HC595 Pin # 11
-DigitalOut DataPin(PTA4); //Pin for to DS of 74HC595 Pin # 14
+DigitalOut LatchPin(PTC7); //Pin for ST_CP of 74HC595 Pin # 12
+DigitalOut ClockPin(PTC0); //Pin for SH_CP of 74HC595 Pin # 11
+DigitalOut DataPin(PTC3); //Pin for to DS of 74HC595 Pin # 14
DigitalOut myled(LED1);
Serial pc(USBTX, USBRX); // tx, rx Serial Output to PC Enabling this WILL consume resources. Use only for debug
+
+uint32_t cbAfterInput(uint32_t index)
+{
+ Index = index;
+ return 0;
+}
+
int main()
{
wait(1);
@@ -50,35 +88,153 @@
blinkAll(4,1);
pc.printf("Done");
wait(1);
- /*
- //Serial pc(USBTX, USBRX); // tx, rx Serial Output to PC Enabling this WILL consume resources. Use only for debug
- while(1) {
- //pc.printf("on");
- myled = 1;
- wait(1);
- //pc.printf("off");
- myled = 0;
- wait(1);
+ State = 1;
+ // r0 r1 r2 r3 c0 c1 c2 c3
+ Keypad keypad(PTD4, PTA12, PTD3, PTA5, PTA13, PTD5, PTD0, PTD2, 20);
+ keypad.attach(&cbAfterInput);
+ keypad.start(); // energize the columns c0-c3 of the keypad
+ while (1) {
+ __wfi();
+ if (Index >-1) {
+ pc.printf("Interrupted");
+ pc.printf("Index:%d => Key:%c\r\n", Index, Keytable[Index]);
+ if (Index == 12) { // Index 12 = Verb Button
+ Verb_Button(); // Goes to Verb_Button
+ }
+ if (Index == 14) { // Index 14 = Noun Button
+ Noun_Button(); // Goes to Noun_Button
+ }
+ if (Index == 11) { // Index 11 = Enter Button
+ Enter_Button(); // Goes to Enter_Button
+ }
+ Index = -1;
+ }
+ // Debug use only
+ //pc.printf("%c", Keytable[Verb_Number1]);
+ //pc.printf("%c", Keytable[Verb_Number2]);
+ //pc.printf("%c", Keytable[Noun_Number1]);
+ //pc.printf("%c", Keytable[Noun_Number2]);
}
- */
- return 0;
+}
+
+/* This function is used when the Verb Button has been pressed. Take the inputs of the button twice and determine if the buttons are integers.
+If other buttons are pressed send it to their perspective locations.
+*/
+void Verb_Button(){
+ Verbz: // Don't Ask
+ // All Variables for Verb, Noun and Enter are zeroed out
+ Verb_Number1 = 0;
+ Verb_Number2 = 0;
+ Noun_Number1 = 0;
+ Noun_Number2 = 0;
+ Enter_Number1 = 0;
+ Enter_Number2 = 0;
+ pc.printf("Please enter a Verb Number");
+ __wfi();
+ Verb_Number1 = Index;
+ if (Verb_Number1 == 12){ // This is section is used on atleast one of the two Verb_Number variabels to prevent a Nestled If within if within if.
+ goto Verbz; // Line 110
+ }
+ else{
+ Button_Sort(Verb_Number1);
+ }
+ //wait(0.01); // Is needed so that Verb_Number1 can store the variable from the keypad. Not sure why it requires an additional job for it to store the data.
+ //pc.printf("%c", Verb_Number1);
+ //pc.printf("%c", Keytable[Index]);
+ __wfi();
+ Verb_Number2 = Index;
+ Button_Sort(Verb_Number2);
+ //wait(0.01); // Is needed so that Verb_Number2 can store the variable form the keypad. Not sure why it requires an additional job for it to store the data.
+ //pc.printf("%c", Verb_Number2);
+ //pc.printf("%c", Verb_Number1);
+ //pc.printf("%c\n", Verb_Number2);
}
-void compare(int Verb,int Noun, int Enter){
- if (Verb == 16 && Noun == 36) {
- //Configure GET
+
+/* This Function is used when the Verb Button has been Pressed. Take the inputs of the button twice and determine if the buttons are integers.
+If other buttons are pressed send it to their perspective locations.
+*/
+void Noun_Button()
+{
+ Nounz:
+ pc.printf("Please enter a Noun Number");
+ __wfi();
+ Noun_Number1 = Index;
+ if (Noun_Number1 == 14) {// This is section is used on atleast one of the two Noun_Number variabels to prevent a Nestled If within if within if.
+ goto Nounz; //Line 140
}
- else if (Verb == 35 && Noun == 100) {
- // Test Light
+ else{
+ Button_Sort(Noun_Number1);
}
- else if (Verb == 25 && Noun == 36) {
+ __wfi();
+ Noun_Number2 = Index;
+ Button_Sort(Noun_Number2);
+}
+
+/* This function is used wen the Enter button has been pressed. This function is a special circumstance since it will be checking both the Verb and Noun variables before entering variable to Enter.
+*/
+void Enter_Button()
+{
+ Enterz:
+ pc.printf("Checking Whether there is a variable stored in Noun\n");
+ if (Noun_Number1 == 0 && Noun_Number2 == 0){
+ pc.printf("Please enter a Enter Number");
+ __wfi();
+ Enter_Number1 = Index;
+ if (Enter_Number1 == 11) { // This section is used on atleast one of the two Enter_Number variable to prevent a nestled if within if within if.
+ goto Enterz;
+ }
+ else{
+ Button_Sort(Enter_Number1);
+ }
+ __wfi();
+ Enter_Number2 = Index;
+ Button_Sort(Enter_Number2);
+ }
+ if (Noun_Number1 != 0 && Noun_Number2 != 0){
+ pc.printf("Check completed, Executing");
+ compare();
+ }
+
+}
+
+// This function is used to sort the button press for Verb and Noun.
+void Button_Sort(int Sort)
+{
+ // Determines what button are pressed before moving on to the 2nd button.
+ if (Sort == 12){ //comparing the array number NOT what value in the array it is. Actual Array value is V
+ Verb_Button();
+ }
+ else if (Sort == 14) { //comparing the array number NOT what value in the array it is. Actual Array value is N
+ Noun_Button();
+ }
+ else if (Sort == 3) { //comparing the array number NOT what value in the array it is. Actual Array value is +
+ pc.printf("+");
+ }
+ else if (Sort == 7) { //comparing the array number NOT what value in the array it is. Actual Array value is -
+ pc.printf("-");
+ }
+ else if (Sort == 15) { //comparing the array number NOT what value in the array it is. Actual Array value is R
+ pc.printf("R");
+ }
+}
+// Compares the button to what program the DSKY should be running. This section will be inefficent until I can improve on my programming skills :]
+void compare()
+{
+ if (Verb_Number1 == 0 && Verb_Number2 == 6 && Noun_Number1 == 2 && Noun_Number2 == 6 && Enter_Number1 == 0 && Enter_Number2 == 0) {// Verb 16, Noun 36, Enter 00
+ //Configure GET
+ pc.printf("Configuring GET");
+ Ground_Elapse_Time();
+ } else if (Verb_Number1 == 3 && Verb_Number2 == 5 && Noun_Number1 == 0 && Noun_Number2 == 0) {
+ // Test Light
+ } else if (Verb == 25 && Noun == 36) {
// Configure GET
- }
- else if (Verb == 37 && Enter == 00) {
+ } else if (Verb == 37 && Enter == 00) {
// Idle Program
- }
}
+}
-void ShiftingOut(int myDataOut) {
+void ShiftingOut(int myDataOut)
+{
// This shifts 8 bits out to the MSB first, The the rising edge of the clock, while clock idles low.
// Internal Fucntions
DataPin = 0;
@@ -88,17 +244,16 @@
// Clears Everything within shift registers
DataPin = 0;
ClockPin = 0;
-
+
for (i=7; i>= 0; i--) {
ClockPin = 0;
-
+
// Value passed to my data out
if ( myDataOut & (1<<i)) {
pinState = 1;
myled = 1;
pc.printf("1");
- }
- else {
+ } else {
pinState = 0;
myled = 0;
pc.printf("0");
@@ -106,13 +261,14 @@
DataPin = pinState;
ClockPin = 1;
DataPin = 0;
- }
+ }
ClockPin = 0;
DataPin = 1;
- }
+}
-//blinks the whole registered based on the number of times you want to blink with a certain delay
-void blinkAll(int amount, int delay){
+//blinks the whole registered based on the number of times you want to blink with a certain delay
+void blinkAll(int amount, int delay)
+{
LatchPin = 0;
ShiftingOut(0);
ShiftingOut(0);
@@ -132,5 +288,11 @@
ShiftingOut(0);
LatchPin = 1;
wait(delay);
- }
- }
\ No newline at end of file
+ }
+}
+
+// Need to fill this too...
+void Ground_Elapse_Time()
+{
+
+}
\ No newline at end of file