A twist to the computer that landed man on the moon. More information can be found at http://hackaday.io/project/294-Open-Source-DSKY
Dependencies: DS1302 keypad mbed
main.cpp@2:aee9ee1296cd, 2014-04-09 (annotated)
- Committer:
- VivaPenguinos
- Date:
- Wed Apr 09 03:00:37 2014 +0000
- Revision:
- 2:aee9ee1296cd
- Parent:
- 1:24446776f0d2
- Child:
- 3:29cff763ae36
DSKY Version 0.02
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
VivaPenguinos | 0:3ff58b093415 | 1 | /* Introduction |
VivaPenguinos | 2:aee9ee1296cd | 2 | MBED DSKY |
VivaPenguinos | 0:3ff58b093415 | 3 | This is a personal project used developed by penguinos to mix old school technology with a modern twist. |
VivaPenguinos | 1:24446776f0d2 | 4 | Version 0.02: March. 4 2014 |
VivaPenguinos | 1:24446776f0d2 | 5 | Added Keypad Functionality |
VivaPenguinos | 1:24446776f0d2 | 6 | - Added fucntion for Verb |
VivaPenguinos | 1:24446776f0d2 | 7 | - Added function for Noun |
VivaPenguinos | 1:24446776f0d2 | 8 | - Added function for Enter |
VivaPenguinos | 1:24446776f0d2 | 9 | - Used goto in Verb and Noun to prevent any nestled Loops. |
VivaPenguinos | 1:24446776f0d2 | 10 | - Contains Button_Sort Function to move location based on button press |
VivaPenguinos | 1:24446776f0d2 | 11 | Cleaned certain parts of the code for efficentcy |
VivaPenguinos | 0:3ff58b093415 | 12 | |
VivaPenguinos | 0:3ff58b093415 | 13 | Notable Credits: |
VivaPenguinos | 0:3ff58b093415 | 14 | NASA! - Release of technical documentations regarding the AGC and DSKY |
VivaPenguinos | 0:3ff58b093415 | 15 | Ron Burkley and Contributers of "Virtual AGC — AGS — LVDC — Gemini" - Providing Technical documentations, Source Code, explanations, |
VivaPenguinos | 0:3ff58b093415 | 16 | and refrences on other sites to make this project successful |
VivaPenguinos | 0:3ff58b093415 | 17 | |
VivaPenguinos | 0:3ff58b093415 | 18 | Warning: This may contain author crude language, random memes, and random thoughts. |
VivaPenguinos | 0:3ff58b093415 | 19 | */ |
VivaPenguinos | 0:3ff58b093415 | 20 | using namespace std; |
VivaPenguinos | 0:3ff58b093415 | 21 | #include "mbed.h" |
VivaPenguinos | 1:24446776f0d2 | 22 | #include "Keypad.h" // Keypad |
VivaPenguinos | 0:3ff58b093415 | 23 | |
VivaPenguinos | 0:3ff58b093415 | 24 | //Declare Variables |
VivaPenguinos | 0:3ff58b093415 | 25 | int shift = 0; // Shift Data |
VivaPenguinos | 0:3ff58b093415 | 26 | // In the Arduino Version it uses a String. Will use an Int instead to see if this works on Mbed |
VivaPenguinos | 1:24446776f0d2 | 27 | int Verb_Number1 = 0; |
VivaPenguinos | 1:24446776f0d2 | 28 | int Verb_Number2 = 0; |
VivaPenguinos | 1:24446776f0d2 | 29 | int Noun_Number1 = 0; |
VivaPenguinos | 1:24446776f0d2 | 30 | int Noun_Number2 = 0; |
VivaPenguinos | 1:24446776f0d2 | 31 | int Enter_Number1 = 0; |
VivaPenguinos | 1:24446776f0d2 | 32 | int Enter_Number2 = 0; |
VivaPenguinos | 1:24446776f0d2 | 33 | int Verb; // DSKY Verb |
VivaPenguinos | 1:24446776f0d2 | 34 | int Noun; // DSkY Noun |
VivaPenguinos | 1:24446776f0d2 | 35 | int Enter; // DSKY Enter |
VivaPenguinos | 0:3ff58b093415 | 36 | int Set_GET_Seconds = 30; // Configure the Set Get in seconds. 1/100th of a second |
VivaPenguinos | 0:3ff58b093415 | 37 | char Set_get_miliseconds = 10; |
VivaPenguinos | 0:3ff58b093415 | 38 | char Set_Get_Seconds_Byte = 0; |
VivaPenguinos | 0:3ff58b093415 | 39 | char Set_Get_Seconds_Byte2 = 0; |
VivaPenguinos | 0:3ff58b093415 | 40 | char data = 0; |
VivaPenguinos | 0:3ff58b093415 | 41 | char data2 = 0; |
VivaPenguinos | 0:3ff58b093415 | 42 | char data3 = 0; |
VivaPenguinos | 1:24446776f0d2 | 43 | char nibble[10] = { // Holds variables for nibbles for number 0-9 in hexes. nibble ALL the things! |
VivaPenguinos | 1:24446776f0d2 | 44 | 0x00, 0x01, 0x02, 0x03, 0x04, |
VivaPenguinos | 1:24446776f0d2 | 45 | 0x05, 0x06, 0x07, 0x08, 0x09 |
VivaPenguinos | 1:24446776f0d2 | 46 | }; |
VivaPenguinos | 1:24446776f0d2 | 47 | |
VivaPenguinos | 1:24446776f0d2 | 48 | char Keytable[] = { '1', '2', '3', '+', // R0 |
VivaPenguinos | 1:24446776f0d2 | 49 | '4', '5', '6', '-', // R1 |
VivaPenguinos | 1:24446776f0d2 | 50 | '7', '8', '9', 'E', // R2 |
VivaPenguinos | 1:24446776f0d2 | 51 | 'V', '0', 'N', 'R', // R3 |
VivaPenguinos | 1:24446776f0d2 | 52 | }; |
VivaPenguinos | 1:24446776f0d2 | 53 | // C0 C1 C2 C3 |
VivaPenguinos | 1:24446776f0d2 | 54 | |
VivaPenguinos | 1:24446776f0d2 | 55 | int32_t Index = -1; // Button |
VivaPenguinos | 1:24446776f0d2 | 56 | int State; |
VivaPenguinos | 0:3ff58b093415 | 57 | |
VivaPenguinos | 0:3ff58b093415 | 58 | // Function Declaration |
VivaPenguinos | 1:24446776f0d2 | 59 | void Verb_Button(); |
VivaPenguinos | 1:24446776f0d2 | 60 | void Noun_Button(); |
VivaPenguinos | 1:24446776f0d2 | 61 | void Enter_Button(); |
VivaPenguinos | 1:24446776f0d2 | 62 | void compare(); |
VivaPenguinos | 1:24446776f0d2 | 63 | void Button_Sort(int sort); // Function that sorts Verb Values |
VivaPenguinos | 0:3ff58b093415 | 64 | void blinkAll(int amount, int delay);// Function that Blinks all LED |
VivaPenguinos | 0:3ff58b093415 | 65 | //void ShiftingOut(char myDataOut); |
VivaPenguinos | 0:3ff58b093415 | 66 | |
VivaPenguinos | 1:24446776f0d2 | 67 | // Program Name |
VivaPenguinos | 1:24446776f0d2 | 68 | void Ground_Elapse_Time(); // Ground Elapse Time |
VivaPenguinos | 1:24446776f0d2 | 69 | |
VivaPenguinos | 0:3ff58b093415 | 70 | // Pin modes for each pins |
VivaPenguinos | 1:24446776f0d2 | 71 | DigitalOut LatchPin(PTC7); //Pin for ST_CP of 74HC595 Pin # 12 |
VivaPenguinos | 1:24446776f0d2 | 72 | DigitalOut ClockPin(PTC0); //Pin for SH_CP of 74HC595 Pin # 11 |
VivaPenguinos | 1:24446776f0d2 | 73 | DigitalOut DataPin(PTC3); //Pin for to DS of 74HC595 Pin # 14 |
VivaPenguinos | 0:3ff58b093415 | 74 | |
VivaPenguinos | 0:3ff58b093415 | 75 | DigitalOut myled(LED1); |
VivaPenguinos | 0:3ff58b093415 | 76 | Serial pc(USBTX, USBRX); // tx, rx Serial Output to PC Enabling this WILL consume resources. Use only for debug |
VivaPenguinos | 1:24446776f0d2 | 77 | |
VivaPenguinos | 1:24446776f0d2 | 78 | uint32_t cbAfterInput(uint32_t index) |
VivaPenguinos | 1:24446776f0d2 | 79 | { |
VivaPenguinos | 1:24446776f0d2 | 80 | Index = index; |
VivaPenguinos | 1:24446776f0d2 | 81 | return 0; |
VivaPenguinos | 1:24446776f0d2 | 82 | } |
VivaPenguinos | 1:24446776f0d2 | 83 | |
VivaPenguinos | 0:3ff58b093415 | 84 | int main() |
VivaPenguinos | 0:3ff58b093415 | 85 | { |
VivaPenguinos | 0:3ff58b093415 | 86 | wait(1); |
VivaPenguinos | 0:3ff58b093415 | 87 | pc.printf("Shifting"); |
VivaPenguinos | 0:3ff58b093415 | 88 | blinkAll(4,1); |
VivaPenguinos | 0:3ff58b093415 | 89 | pc.printf("Done"); |
VivaPenguinos | 0:3ff58b093415 | 90 | wait(1); |
VivaPenguinos | 1:24446776f0d2 | 91 | State = 1; |
VivaPenguinos | 1:24446776f0d2 | 92 | // r0 r1 r2 r3 c0 c1 c2 c3 |
VivaPenguinos | 1:24446776f0d2 | 93 | Keypad keypad(PTD4, PTA12, PTD3, PTA5, PTA13, PTD5, PTD0, PTD2, 20); |
VivaPenguinos | 1:24446776f0d2 | 94 | keypad.attach(&cbAfterInput); |
VivaPenguinos | 1:24446776f0d2 | 95 | keypad.start(); // energize the columns c0-c3 of the keypad |
VivaPenguinos | 1:24446776f0d2 | 96 | while (1) { |
VivaPenguinos | 1:24446776f0d2 | 97 | __wfi(); |
VivaPenguinos | 1:24446776f0d2 | 98 | if (Index >-1) { |
VivaPenguinos | 1:24446776f0d2 | 99 | pc.printf("Interrupted"); |
VivaPenguinos | 1:24446776f0d2 | 100 | pc.printf("Index:%d => Key:%c\r\n", Index, Keytable[Index]); |
VivaPenguinos | 1:24446776f0d2 | 101 | if (Index == 12) { // Index 12 = Verb Button |
VivaPenguinos | 1:24446776f0d2 | 102 | Verb_Button(); // Goes to Verb_Button |
VivaPenguinos | 1:24446776f0d2 | 103 | } |
VivaPenguinos | 1:24446776f0d2 | 104 | if (Index == 14) { // Index 14 = Noun Button |
VivaPenguinos | 1:24446776f0d2 | 105 | Noun_Button(); // Goes to Noun_Button |
VivaPenguinos | 1:24446776f0d2 | 106 | } |
VivaPenguinos | 1:24446776f0d2 | 107 | if (Index == 11) { // Index 11 = Enter Button |
VivaPenguinos | 1:24446776f0d2 | 108 | Enter_Button(); // Goes to Enter_Button |
VivaPenguinos | 1:24446776f0d2 | 109 | } |
VivaPenguinos | 1:24446776f0d2 | 110 | Index = -1; |
VivaPenguinos | 1:24446776f0d2 | 111 | } |
VivaPenguinos | 1:24446776f0d2 | 112 | // Debug use only |
VivaPenguinos | 1:24446776f0d2 | 113 | //pc.printf("%c", Keytable[Verb_Number1]); |
VivaPenguinos | 1:24446776f0d2 | 114 | //pc.printf("%c", Keytable[Verb_Number2]); |
VivaPenguinos | 1:24446776f0d2 | 115 | //pc.printf("%c", Keytable[Noun_Number1]); |
VivaPenguinos | 1:24446776f0d2 | 116 | //pc.printf("%c", Keytable[Noun_Number2]); |
VivaPenguinos | 0:3ff58b093415 | 117 | } |
VivaPenguinos | 1:24446776f0d2 | 118 | } |
VivaPenguinos | 1:24446776f0d2 | 119 | |
VivaPenguinos | 1:24446776f0d2 | 120 | /* 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. |
VivaPenguinos | 1:24446776f0d2 | 121 | If other buttons are pressed send it to their perspective locations. |
VivaPenguinos | 1:24446776f0d2 | 122 | */ |
VivaPenguinos | 1:24446776f0d2 | 123 | void Verb_Button(){ |
VivaPenguinos | 1:24446776f0d2 | 124 | Verbz: // Don't Ask |
VivaPenguinos | 1:24446776f0d2 | 125 | // All Variables for Verb, Noun and Enter are zeroed out |
VivaPenguinos | 1:24446776f0d2 | 126 | Verb_Number1 = 0; |
VivaPenguinos | 1:24446776f0d2 | 127 | Verb_Number2 = 0; |
VivaPenguinos | 1:24446776f0d2 | 128 | Noun_Number1 = 0; |
VivaPenguinos | 1:24446776f0d2 | 129 | Noun_Number2 = 0; |
VivaPenguinos | 1:24446776f0d2 | 130 | Enter_Number1 = 0; |
VivaPenguinos | 1:24446776f0d2 | 131 | Enter_Number2 = 0; |
VivaPenguinos | 1:24446776f0d2 | 132 | pc.printf("Please enter a Verb Number"); |
VivaPenguinos | 1:24446776f0d2 | 133 | __wfi(); |
VivaPenguinos | 1:24446776f0d2 | 134 | Verb_Number1 = Index; |
VivaPenguinos | 1:24446776f0d2 | 135 | 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. |
VivaPenguinos | 1:24446776f0d2 | 136 | goto Verbz; // Line 110 |
VivaPenguinos | 1:24446776f0d2 | 137 | } |
VivaPenguinos | 1:24446776f0d2 | 138 | else{ |
VivaPenguinos | 1:24446776f0d2 | 139 | Button_Sort(Verb_Number1); |
VivaPenguinos | 1:24446776f0d2 | 140 | } |
VivaPenguinos | 1:24446776f0d2 | 141 | //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. |
VivaPenguinos | 1:24446776f0d2 | 142 | //pc.printf("%c", Verb_Number1); |
VivaPenguinos | 1:24446776f0d2 | 143 | //pc.printf("%c", Keytable[Index]); |
VivaPenguinos | 1:24446776f0d2 | 144 | __wfi(); |
VivaPenguinos | 1:24446776f0d2 | 145 | Verb_Number2 = Index; |
VivaPenguinos | 1:24446776f0d2 | 146 | Button_Sort(Verb_Number2); |
VivaPenguinos | 1:24446776f0d2 | 147 | //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. |
VivaPenguinos | 1:24446776f0d2 | 148 | //pc.printf("%c", Verb_Number2); |
VivaPenguinos | 1:24446776f0d2 | 149 | //pc.printf("%c", Verb_Number1); |
VivaPenguinos | 1:24446776f0d2 | 150 | //pc.printf("%c\n", Verb_Number2); |
VivaPenguinos | 0:3ff58b093415 | 151 | } |
VivaPenguinos | 1:24446776f0d2 | 152 | |
VivaPenguinos | 1:24446776f0d2 | 153 | /* 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. |
VivaPenguinos | 1:24446776f0d2 | 154 | If other buttons are pressed send it to their perspective locations. |
VivaPenguinos | 1:24446776f0d2 | 155 | */ |
VivaPenguinos | 1:24446776f0d2 | 156 | void Noun_Button() |
VivaPenguinos | 1:24446776f0d2 | 157 | { |
VivaPenguinos | 1:24446776f0d2 | 158 | Nounz: |
VivaPenguinos | 1:24446776f0d2 | 159 | pc.printf("Please enter a Noun Number"); |
VivaPenguinos | 1:24446776f0d2 | 160 | __wfi(); |
VivaPenguinos | 1:24446776f0d2 | 161 | Noun_Number1 = Index; |
VivaPenguinos | 1:24446776f0d2 | 162 | 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. |
VivaPenguinos | 1:24446776f0d2 | 163 | goto Nounz; //Line 140 |
VivaPenguinos | 0:3ff58b093415 | 164 | } |
VivaPenguinos | 1:24446776f0d2 | 165 | else{ |
VivaPenguinos | 1:24446776f0d2 | 166 | Button_Sort(Noun_Number1); |
VivaPenguinos | 0:3ff58b093415 | 167 | } |
VivaPenguinos | 1:24446776f0d2 | 168 | __wfi(); |
VivaPenguinos | 1:24446776f0d2 | 169 | Noun_Number2 = Index; |
VivaPenguinos | 1:24446776f0d2 | 170 | Button_Sort(Noun_Number2); |
VivaPenguinos | 1:24446776f0d2 | 171 | } |
VivaPenguinos | 1:24446776f0d2 | 172 | |
VivaPenguinos | 1:24446776f0d2 | 173 | /* 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. |
VivaPenguinos | 1:24446776f0d2 | 174 | */ |
VivaPenguinos | 1:24446776f0d2 | 175 | void Enter_Button() |
VivaPenguinos | 1:24446776f0d2 | 176 | { |
VivaPenguinos | 1:24446776f0d2 | 177 | Enterz: |
VivaPenguinos | 1:24446776f0d2 | 178 | pc.printf("Checking Whether there is a variable stored in Noun\n"); |
VivaPenguinos | 1:24446776f0d2 | 179 | if (Noun_Number1 == 0 && Noun_Number2 == 0){ |
VivaPenguinos | 1:24446776f0d2 | 180 | pc.printf("Please enter a Enter Number"); |
VivaPenguinos | 1:24446776f0d2 | 181 | __wfi(); |
VivaPenguinos | 1:24446776f0d2 | 182 | Enter_Number1 = Index; |
VivaPenguinos | 1:24446776f0d2 | 183 | 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. |
VivaPenguinos | 1:24446776f0d2 | 184 | goto Enterz; |
VivaPenguinos | 1:24446776f0d2 | 185 | } |
VivaPenguinos | 1:24446776f0d2 | 186 | else{ |
VivaPenguinos | 1:24446776f0d2 | 187 | Button_Sort(Enter_Number1); |
VivaPenguinos | 1:24446776f0d2 | 188 | } |
VivaPenguinos | 1:24446776f0d2 | 189 | __wfi(); |
VivaPenguinos | 1:24446776f0d2 | 190 | Enter_Number2 = Index; |
VivaPenguinos | 1:24446776f0d2 | 191 | Button_Sort(Enter_Number2); |
VivaPenguinos | 1:24446776f0d2 | 192 | } |
VivaPenguinos | 1:24446776f0d2 | 193 | if (Noun_Number1 != 0 && Noun_Number2 != 0){ |
VivaPenguinos | 1:24446776f0d2 | 194 | pc.printf("Check completed, Executing"); |
VivaPenguinos | 1:24446776f0d2 | 195 | compare(); |
VivaPenguinos | 1:24446776f0d2 | 196 | } |
VivaPenguinos | 1:24446776f0d2 | 197 | |
VivaPenguinos | 1:24446776f0d2 | 198 | } |
VivaPenguinos | 1:24446776f0d2 | 199 | |
VivaPenguinos | 1:24446776f0d2 | 200 | // This function is used to sort the button press for Verb and Noun. |
VivaPenguinos | 1:24446776f0d2 | 201 | void Button_Sort(int Sort) |
VivaPenguinos | 1:24446776f0d2 | 202 | { |
VivaPenguinos | 1:24446776f0d2 | 203 | // Determines what button are pressed before moving on to the 2nd button. |
VivaPenguinos | 1:24446776f0d2 | 204 | if (Sort == 12){ //comparing the array number NOT what value in the array it is. Actual Array value is V |
VivaPenguinos | 1:24446776f0d2 | 205 | Verb_Button(); |
VivaPenguinos | 1:24446776f0d2 | 206 | } |
VivaPenguinos | 1:24446776f0d2 | 207 | else if (Sort == 14) { //comparing the array number NOT what value in the array it is. Actual Array value is N |
VivaPenguinos | 1:24446776f0d2 | 208 | Noun_Button(); |
VivaPenguinos | 1:24446776f0d2 | 209 | } |
VivaPenguinos | 1:24446776f0d2 | 210 | else if (Sort == 3) { //comparing the array number NOT what value in the array it is. Actual Array value is + |
VivaPenguinos | 1:24446776f0d2 | 211 | pc.printf("+"); |
VivaPenguinos | 1:24446776f0d2 | 212 | } |
VivaPenguinos | 1:24446776f0d2 | 213 | else if (Sort == 7) { //comparing the array number NOT what value in the array it is. Actual Array value is - |
VivaPenguinos | 1:24446776f0d2 | 214 | pc.printf("-"); |
VivaPenguinos | 1:24446776f0d2 | 215 | } |
VivaPenguinos | 1:24446776f0d2 | 216 | else if (Sort == 15) { //comparing the array number NOT what value in the array it is. Actual Array value is R |
VivaPenguinos | 1:24446776f0d2 | 217 | pc.printf("R"); |
VivaPenguinos | 1:24446776f0d2 | 218 | } |
VivaPenguinos | 1:24446776f0d2 | 219 | } |
VivaPenguinos | 1:24446776f0d2 | 220 | // Compares the button to what program the DSKY should be running. This section will be inefficent until I can improve on my programming skills :] |
VivaPenguinos | 1:24446776f0d2 | 221 | void compare() |
VivaPenguinos | 1:24446776f0d2 | 222 | { |
VivaPenguinos | 1:24446776f0d2 | 223 | 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 |
VivaPenguinos | 1:24446776f0d2 | 224 | //Configure GET |
VivaPenguinos | 1:24446776f0d2 | 225 | pc.printf("Configuring GET"); |
VivaPenguinos | 1:24446776f0d2 | 226 | Ground_Elapse_Time(); |
VivaPenguinos | 1:24446776f0d2 | 227 | } else if (Verb_Number1 == 3 && Verb_Number2 == 5 && Noun_Number1 == 0 && Noun_Number2 == 0) { |
VivaPenguinos | 1:24446776f0d2 | 228 | // Test Light |
VivaPenguinos | 1:24446776f0d2 | 229 | } else if (Verb == 25 && Noun == 36) { |
VivaPenguinos | 0:3ff58b093415 | 230 | // Configure GET |
VivaPenguinos | 1:24446776f0d2 | 231 | } else if (Verb == 37 && Enter == 00) { |
VivaPenguinos | 0:3ff58b093415 | 232 | // Idle Program |
VivaPenguinos | 0:3ff58b093415 | 233 | } |
VivaPenguinos | 1:24446776f0d2 | 234 | } |
VivaPenguinos | 0:3ff58b093415 | 235 | |
VivaPenguinos | 1:24446776f0d2 | 236 | void ShiftingOut(int myDataOut) |
VivaPenguinos | 1:24446776f0d2 | 237 | { |
VivaPenguinos | 0:3ff58b093415 | 238 | // This shifts 8 bits out to the MSB first, The the rising edge of the clock, while clock idles low. |
VivaPenguinos | 0:3ff58b093415 | 239 | // Internal Fucntions |
VivaPenguinos | 0:3ff58b093415 | 240 | DataPin = 0; |
VivaPenguinos | 0:3ff58b093415 | 241 | ClockPin = 0; |
VivaPenguinos | 0:3ff58b093415 | 242 | int i= 0; |
VivaPenguinos | 0:3ff58b093415 | 243 | int pinState; |
VivaPenguinos | 0:3ff58b093415 | 244 | // Clears Everything within shift registers |
VivaPenguinos | 0:3ff58b093415 | 245 | DataPin = 0; |
VivaPenguinos | 0:3ff58b093415 | 246 | ClockPin = 0; |
VivaPenguinos | 1:24446776f0d2 | 247 | |
VivaPenguinos | 0:3ff58b093415 | 248 | for (i=7; i>= 0; i--) { |
VivaPenguinos | 0:3ff58b093415 | 249 | ClockPin = 0; |
VivaPenguinos | 1:24446776f0d2 | 250 | |
VivaPenguinos | 0:3ff58b093415 | 251 | // Value passed to my data out |
VivaPenguinos | 0:3ff58b093415 | 252 | if ( myDataOut & (1<<i)) { |
VivaPenguinos | 0:3ff58b093415 | 253 | pinState = 1; |
VivaPenguinos | 0:3ff58b093415 | 254 | myled = 1; |
VivaPenguinos | 0:3ff58b093415 | 255 | pc.printf("1"); |
VivaPenguinos | 1:24446776f0d2 | 256 | } else { |
VivaPenguinos | 0:3ff58b093415 | 257 | pinState = 0; |
VivaPenguinos | 0:3ff58b093415 | 258 | myled = 0; |
VivaPenguinos | 0:3ff58b093415 | 259 | pc.printf("0"); |
VivaPenguinos | 0:3ff58b093415 | 260 | } |
VivaPenguinos | 0:3ff58b093415 | 261 | DataPin = pinState; |
VivaPenguinos | 0:3ff58b093415 | 262 | ClockPin = 1; |
VivaPenguinos | 0:3ff58b093415 | 263 | DataPin = 0; |
VivaPenguinos | 1:24446776f0d2 | 264 | } |
VivaPenguinos | 0:3ff58b093415 | 265 | ClockPin = 0; |
VivaPenguinos | 0:3ff58b093415 | 266 | DataPin = 1; |
VivaPenguinos | 1:24446776f0d2 | 267 | } |
VivaPenguinos | 0:3ff58b093415 | 268 | |
VivaPenguinos | 1:24446776f0d2 | 269 | //blinks the whole registered based on the number of times you want to blink with a certain delay |
VivaPenguinos | 1:24446776f0d2 | 270 | void blinkAll(int amount, int delay) |
VivaPenguinos | 1:24446776f0d2 | 271 | { |
VivaPenguinos | 0:3ff58b093415 | 272 | LatchPin = 0; |
VivaPenguinos | 0:3ff58b093415 | 273 | ShiftingOut(0); |
VivaPenguinos | 0:3ff58b093415 | 274 | ShiftingOut(0); |
VivaPenguinos | 0:3ff58b093415 | 275 | LatchPin = 1; |
VivaPenguinos | 0:3ff58b093415 | 276 | wait(0.2); |
VivaPenguinos | 0:3ff58b093415 | 277 | for (int x = 0; x < amount; x++) { |
VivaPenguinos | 0:3ff58b093415 | 278 | LatchPin = 0; |
VivaPenguinos | 0:3ff58b093415 | 279 | pc.printf("sending"); |
VivaPenguinos | 0:3ff58b093415 | 280 | ShiftingOut(255); |
VivaPenguinos | 0:3ff58b093415 | 281 | ShiftingOut(255); |
VivaPenguinos | 0:3ff58b093415 | 282 | ShiftingOut(255); |
VivaPenguinos | 0:3ff58b093415 | 283 | LatchPin = 1; |
VivaPenguinos | 0:3ff58b093415 | 284 | wait(delay); |
VivaPenguinos | 0:3ff58b093415 | 285 | LatchPin = 0; |
VivaPenguinos | 0:3ff58b093415 | 286 | ShiftingOut(0); |
VivaPenguinos | 0:3ff58b093415 | 287 | ShiftingOut(0); |
VivaPenguinos | 0:3ff58b093415 | 288 | ShiftingOut(0); |
VivaPenguinos | 0:3ff58b093415 | 289 | LatchPin = 1; |
VivaPenguinos | 0:3ff58b093415 | 290 | wait(delay); |
VivaPenguinos | 1:24446776f0d2 | 291 | } |
VivaPenguinos | 1:24446776f0d2 | 292 | } |
VivaPenguinos | 1:24446776f0d2 | 293 | |
VivaPenguinos | 1:24446776f0d2 | 294 | // Need to fill this too... |
VivaPenguinos | 1:24446776f0d2 | 295 | void Ground_Elapse_Time() |
VivaPenguinos | 1:24446776f0d2 | 296 | { |
VivaPenguinos | 1:24446776f0d2 | 297 | |
VivaPenguinos | 1:24446776f0d2 | 298 | } |