Cambio de parametros PID con tres pulsadores (incremental, decremental y cambio) con sonido
Dependencies: Debounced TextLCD mbed
Fork of pid_teclas by
main.cpp@1:ab52c079267a, 2014-04-23 (annotated)
- Committer:
- Jepalacioh
- Date:
- Wed Apr 23 15:03:43 2014 +0000
- Revision:
- 1:ab52c079267a
- Parent:
- 0:9aa80672eb3d
Tarea2 Procesadores UNAL semestre 2014-1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Jepalacioh | 1:ab52c079267a | 1 | //Este programa se basó en el programa de tony63 teclas_PID |
Jepalacioh | 1:ab52c079267a | 2 | |
Jepalacioh | 1:ab52c079267a | 3 | |
Jepalacioh | 1:ab52c079267a | 4 | //Julian Esteban Palacio Hernandez |
Jepalacioh | 1:ab52c079267a | 5 | //Andres Mauricio Gomez Arevalo |
Jepalacioh | 1:ab52c079267a | 6 | |
lcorralesc1 | 0:9aa80672eb3d | 7 | #include "mbed.h" |
lcorralesc1 | 0:9aa80672eb3d | 8 | #include "DebouncedIn.h" |
lcorralesc1 | 0:9aa80672eb3d | 9 | #include "TextLCD.h" |
lcorralesc1 | 0:9aa80672eb3d | 10 | |
lcorralesc1 | 0:9aa80672eb3d | 11 | AnalogIn Vin(PTC2); |
lcorralesc1 | 0:9aa80672eb3d | 12 | TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); // rs, e, d4-d7 |
lcorralesc1 | 0:9aa80672eb3d | 13 | |
lcorralesc1 | 0:9aa80672eb3d | 14 | DigitalOut led1(LED1); |
lcorralesc1 | 0:9aa80672eb3d | 15 | DigitalOut led2(LED2); |
lcorralesc1 | 0:9aa80672eb3d | 16 | DigitalOut led3(LED3); |
lcorralesc1 | 0:9aa80672eb3d | 17 | DebouncedIn button1(PTC12); |
lcorralesc1 | 0:9aa80672eb3d | 18 | DebouncedIn button2(PTC13); |
lcorralesc1 | 0:9aa80672eb3d | 19 | DebouncedIn button3(PTC16); |
lcorralesc1 | 0:9aa80672eb3d | 20 | |
Jepalacioh | 1:ab52c079267a | 21 | PwmOut Sonido(PTA5); |
Jepalacioh | 1:ab52c079267a | 22 | |
Jepalacioh | 1:ab52c079267a | 23 | |
Jepalacioh | 1:ab52c079267a | 24 | float periodo; |
Jepalacioh | 1:ab52c079267a | 25 | float Frecuencia=1000; |
lcorralesc1 | 0:9aa80672eb3d | 26 | int C1=0x0F; |
lcorralesc1 | 0:9aa80672eb3d | 27 | int sp=0,kp=0,kd=0,ki=0,p=1; |
lcorralesc1 | 0:9aa80672eb3d | 28 | int main() |
lcorralesc1 | 0:9aa80672eb3d | 29 | { |
lcorralesc1 | 0:9aa80672eb3d | 30 | lcd.cls(); |
lcorralesc1 | 0:9aa80672eb3d | 31 | lcd.writeCommand(C1);//escribimos un comando segun el manual del modulo LCD |
lcorralesc1 | 0:9aa80672eb3d | 32 | lcd.locate(8,0); |
lcorralesc1 | 0:9aa80672eb3d | 33 | lcd.printf("kp=%d", kp); |
lcorralesc1 | 0:9aa80672eb3d | 34 | lcd.locate(0,1); |
lcorralesc1 | 0:9aa80672eb3d | 35 | lcd.printf("Ki=%d", ki); |
lcorralesc1 | 0:9aa80672eb3d | 36 | lcd.locate(8,1); |
lcorralesc1 | 0:9aa80672eb3d | 37 | lcd.printf("Kd=%d", kd); |
lcorralesc1 | 0:9aa80672eb3d | 38 | lcd.locate(0,0); |
lcorralesc1 | 0:9aa80672eb3d | 39 | lcd.printf("Sp=%d", sp); |
lcorralesc1 | 0:9aa80672eb3d | 40 | |
lcorralesc1 | 0:9aa80672eb3d | 41 | while(1) |
lcorralesc1 | 0:9aa80672eb3d | 42 | { |
Jepalacioh | 1:ab52c079267a | 43 | |
Jepalacioh | 1:ab52c079267a | 44 | periodo=(1/Frecuencia); |
Jepalacioh | 1:ab52c079267a | 45 | Sonido.period(periodo); |
Jepalacioh | 1:ab52c079267a | 46 | |
Jepalacioh | 1:ab52c079267a | 47 | |
lcorralesc1 | 0:9aa80672eb3d | 48 | if (button1.falling()) |
lcorralesc1 | 0:9aa80672eb3d | 49 | { |
Jepalacioh | 1:ab52c079267a | 50 | |
Jepalacioh | 1:ab52c079267a | 51 | Sonido.write(0.5); |
Jepalacioh | 1:ab52c079267a | 52 | wait(0.1); |
Jepalacioh | 1:ab52c079267a | 53 | Sonido.write(0); |
lcorralesc1 | 0:9aa80672eb3d | 54 | led1 =!led1; |
lcorralesc1 | 0:9aa80672eb3d | 55 | if (p==1) |
lcorralesc1 | 0:9aa80672eb3d | 56 | { |
lcorralesc1 | 0:9aa80672eb3d | 57 | ++sp; |
lcorralesc1 | 0:9aa80672eb3d | 58 | lcd.locate(3,0); |
lcorralesc1 | 0:9aa80672eb3d | 59 | lcd.printf(" "); |
lcorralesc1 | 0:9aa80672eb3d | 60 | lcd.locate(3,0); |
lcorralesc1 | 0:9aa80672eb3d | 61 | lcd.printf("%d", sp); |
lcorralesc1 | 0:9aa80672eb3d | 62 | } |
lcorralesc1 | 0:9aa80672eb3d | 63 | else if (p==2) |
lcorralesc1 | 0:9aa80672eb3d | 64 | { |
lcorralesc1 | 0:9aa80672eb3d | 65 | ++kp; |
lcorralesc1 | 0:9aa80672eb3d | 66 | lcd.locate(11,0); |
lcorralesc1 | 0:9aa80672eb3d | 67 | lcd.printf(" "); |
lcorralesc1 | 0:9aa80672eb3d | 68 | lcd.locate(11,0); |
lcorralesc1 | 0:9aa80672eb3d | 69 | lcd.printf("%d", kp); |
lcorralesc1 | 0:9aa80672eb3d | 70 | } |
lcorralesc1 | 0:9aa80672eb3d | 71 | else if (p==3) |
lcorralesc1 | 0:9aa80672eb3d | 72 | { |
lcorralesc1 | 0:9aa80672eb3d | 73 | ++ki; |
lcorralesc1 | 0:9aa80672eb3d | 74 | lcd.locate(3,1); |
lcorralesc1 | 0:9aa80672eb3d | 75 | lcd.printf(" "); |
lcorralesc1 | 0:9aa80672eb3d | 76 | lcd.locate(3,1); |
lcorralesc1 | 0:9aa80672eb3d | 77 | lcd.printf("%d", ki); |
lcorralesc1 | 0:9aa80672eb3d | 78 | } |
lcorralesc1 | 0:9aa80672eb3d | 79 | else if (p==4) |
lcorralesc1 | 0:9aa80672eb3d | 80 | { |
lcorralesc1 | 0:9aa80672eb3d | 81 | ++kd; |
lcorralesc1 | 0:9aa80672eb3d | 82 | lcd.locate(11,1); |
lcorralesc1 | 0:9aa80672eb3d | 83 | lcd.printf(" "); |
lcorralesc1 | 0:9aa80672eb3d | 84 | lcd.locate(11,1); |
lcorralesc1 | 0:9aa80672eb3d | 85 | lcd.printf("%d", kd); |
lcorralesc1 | 0:9aa80672eb3d | 86 | } |
lcorralesc1 | 0:9aa80672eb3d | 87 | } |
lcorralesc1 | 0:9aa80672eb3d | 88 | if (button2.falling()) |
lcorralesc1 | 0:9aa80672eb3d | 89 | { |
Jepalacioh | 1:ab52c079267a | 90 | |
Jepalacioh | 1:ab52c079267a | 91 | Sonido.write(0.5); |
Jepalacioh | 1:ab52c079267a | 92 | wait(0.1); |
Jepalacioh | 1:ab52c079267a | 93 | Sonido.write(0); |
lcorralesc1 | 0:9aa80672eb3d | 94 | led2 =!led2; |
lcorralesc1 | 0:9aa80672eb3d | 95 | if (p==1) |
lcorralesc1 | 0:9aa80672eb3d | 96 | { |
lcorralesc1 | 0:9aa80672eb3d | 97 | if (sp==0) // no mostrar nada |
lcorralesc1 | 0:9aa80672eb3d | 98 | { |
lcorralesc1 | 0:9aa80672eb3d | 99 | } |
lcorralesc1 | 0:9aa80672eb3d | 100 | else |
lcorralesc1 | 0:9aa80672eb3d | 101 | { |
lcorralesc1 | 0:9aa80672eb3d | 102 | --sp; |
lcorralesc1 | 0:9aa80672eb3d | 103 | lcd.locate(3,0); |
lcorralesc1 | 0:9aa80672eb3d | 104 | lcd.printf(" "); |
lcorralesc1 | 0:9aa80672eb3d | 105 | lcd.locate(3,0); |
lcorralesc1 | 0:9aa80672eb3d | 106 | lcd.printf("%d", sp); |
lcorralesc1 | 0:9aa80672eb3d | 107 | } |
lcorralesc1 | 0:9aa80672eb3d | 108 | } |
lcorralesc1 | 0:9aa80672eb3d | 109 | if (p==2) |
lcorralesc1 | 0:9aa80672eb3d | 110 | { |
lcorralesc1 | 0:9aa80672eb3d | 111 | if (kp==0) // no mostrar nada |
lcorralesc1 | 0:9aa80672eb3d | 112 | { |
lcorralesc1 | 0:9aa80672eb3d | 113 | } |
lcorralesc1 | 0:9aa80672eb3d | 114 | else |
lcorralesc1 | 0:9aa80672eb3d | 115 | { |
lcorralesc1 | 0:9aa80672eb3d | 116 | --kp; |
lcorralesc1 | 0:9aa80672eb3d | 117 | lcd.locate(11,0); |
lcorralesc1 | 0:9aa80672eb3d | 118 | lcd.printf(" "); |
lcorralesc1 | 0:9aa80672eb3d | 119 | lcd.locate(11,0); |
lcorralesc1 | 0:9aa80672eb3d | 120 | lcd.printf("%d", kp); |
lcorralesc1 | 0:9aa80672eb3d | 121 | } |
lcorralesc1 | 0:9aa80672eb3d | 122 | } |
lcorralesc1 | 0:9aa80672eb3d | 123 | if (p==3) |
lcorralesc1 | 0:9aa80672eb3d | 124 | { |
lcorralesc1 | 0:9aa80672eb3d | 125 | if (ki==0) // no mostrar nada |
lcorralesc1 | 0:9aa80672eb3d | 126 | { |
lcorralesc1 | 0:9aa80672eb3d | 127 | } |
lcorralesc1 | 0:9aa80672eb3d | 128 | else |
lcorralesc1 | 0:9aa80672eb3d | 129 | { |
lcorralesc1 | 0:9aa80672eb3d | 130 | --ki; |
lcorralesc1 | 0:9aa80672eb3d | 131 | lcd.locate(3,1); |
lcorralesc1 | 0:9aa80672eb3d | 132 | lcd.printf(" "); |
lcorralesc1 | 0:9aa80672eb3d | 133 | lcd.locate(3,1); |
lcorralesc1 | 0:9aa80672eb3d | 134 | lcd.printf("%d", ki); |
lcorralesc1 | 0:9aa80672eb3d | 135 | } |
lcorralesc1 | 0:9aa80672eb3d | 136 | } |
lcorralesc1 | 0:9aa80672eb3d | 137 | if (p==4) |
lcorralesc1 | 0:9aa80672eb3d | 138 | { |
lcorralesc1 | 0:9aa80672eb3d | 139 | if (kd==0) // no mostrar nada |
lcorralesc1 | 0:9aa80672eb3d | 140 | { |
lcorralesc1 | 0:9aa80672eb3d | 141 | } |
lcorralesc1 | 0:9aa80672eb3d | 142 | else |
lcorralesc1 | 0:9aa80672eb3d | 143 | { |
lcorralesc1 | 0:9aa80672eb3d | 144 | --kd; |
lcorralesc1 | 0:9aa80672eb3d | 145 | lcd.locate(11,1); |
lcorralesc1 | 0:9aa80672eb3d | 146 | lcd.printf(" "); |
lcorralesc1 | 0:9aa80672eb3d | 147 | lcd.locate(11,1); |
lcorralesc1 | 0:9aa80672eb3d | 148 | lcd.printf("%d", kd); |
lcorralesc1 | 0:9aa80672eb3d | 149 | } |
lcorralesc1 | 0:9aa80672eb3d | 150 | } |
lcorralesc1 | 0:9aa80672eb3d | 151 | } |
lcorralesc1 | 0:9aa80672eb3d | 152 | if (button3.falling()) |
lcorralesc1 | 0:9aa80672eb3d | 153 | { |
Jepalacioh | 1:ab52c079267a | 154 | |
Jepalacioh | 1:ab52c079267a | 155 | Sonido.write(0.5); |
Jepalacioh | 1:ab52c079267a | 156 | wait(0.1); |
Jepalacioh | 1:ab52c079267a | 157 | Sonido.write(0); |
lcorralesc1 | 0:9aa80672eb3d | 158 | led3 =!led3; |
lcorralesc1 | 0:9aa80672eb3d | 159 | if (p==1) |
lcorralesc1 | 0:9aa80672eb3d | 160 | { |
lcorralesc1 | 0:9aa80672eb3d | 161 | ++p; |
lcorralesc1 | 0:9aa80672eb3d | 162 | lcd.locate(11,0); |
lcorralesc1 | 0:9aa80672eb3d | 163 | lcd.printf("%d", kp); |
lcorralesc1 | 0:9aa80672eb3d | 164 | |
lcorralesc1 | 0:9aa80672eb3d | 165 | |
lcorralesc1 | 0:9aa80672eb3d | 166 | } |
lcorralesc1 | 0:9aa80672eb3d | 167 | else if (p==2) |
lcorralesc1 | 0:9aa80672eb3d | 168 | { |
lcorralesc1 | 0:9aa80672eb3d | 169 | ++p; |
lcorralesc1 | 0:9aa80672eb3d | 170 | lcd.locate(3,1); |
lcorralesc1 | 0:9aa80672eb3d | 171 | lcd.printf("%d", ki); |
lcorralesc1 | 0:9aa80672eb3d | 172 | lcd.locate(3,1); |
lcorralesc1 | 0:9aa80672eb3d | 173 | |
lcorralesc1 | 0:9aa80672eb3d | 174 | } |
lcorralesc1 | 0:9aa80672eb3d | 175 | else if (p==3) |
lcorralesc1 | 0:9aa80672eb3d | 176 | { |
lcorralesc1 | 0:9aa80672eb3d | 177 | ++p; |
lcorralesc1 | 0:9aa80672eb3d | 178 | lcd.locate(11,1); |
lcorralesc1 | 0:9aa80672eb3d | 179 | lcd.printf("%d", kd); |
lcorralesc1 | 0:9aa80672eb3d | 180 | |
lcorralesc1 | 0:9aa80672eb3d | 181 | |
lcorralesc1 | 0:9aa80672eb3d | 182 | } |
lcorralesc1 | 0:9aa80672eb3d | 183 | else if (p==4) |
lcorralesc1 | 0:9aa80672eb3d | 184 | { |
lcorralesc1 | 0:9aa80672eb3d | 185 | p=1; |
lcorralesc1 | 0:9aa80672eb3d | 186 | lcd.locate(3,0); |
lcorralesc1 | 0:9aa80672eb3d | 187 | lcd.printf("%d", sp); |
lcorralesc1 | 0:9aa80672eb3d | 188 | |
lcorralesc1 | 0:9aa80672eb3d | 189 | |
lcorralesc1 | 0:9aa80672eb3d | 190 | } |
lcorralesc1 | 0:9aa80672eb3d | 191 | } |
lcorralesc1 | 0:9aa80672eb3d | 192 | } |
lcorralesc1 | 0:9aa80672eb3d | 193 | } |