pot controller voor positie, kp handmatig instellen, werkt met motor 1 en 2

Dependencies:   MODSERIAL QEI mbed-dsp mbed

Fork of PI_controller_verbeteringen by ProjectGroep23

Committer:
SimonRez
Date:
Wed Sep 12 12:18:25 2018 +0000
Revision:
4:651d06e860e7
Parent:
3:40a25c2c24ba
Child:
5:f07bafaf11d7
SW2 checkt de kleur en geeft hem aan via serial; SW3 zet de led lamp uit en alle waarden van variabelen op NULL

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vsluiter 0:c8f15874531b 1 #include "mbed.h"
vsluiter 0:c8f15874531b 2 #include "MODSERIAL.h"
vsluiter 0:c8f15874531b 3
SimonRez 2:52b3c0b95388 4 Ticker Blinker;
SimonRez 2:52b3c0b95388 5
SimonRez 2:52b3c0b95388 6 DigitalOut ledr(LED_RED);
SimonRez 2:52b3c0b95388 7 DigitalOut ledg(LED_GREEN);
SimonRez 2:52b3c0b95388 8 DigitalOut ledb(LED_BLUE);
SimonRez 4:651d06e860e7 9
SimonRez 4:651d06e860e7 10 InterruptIn sw2(SW2);
SimonRez 4:651d06e860e7 11 InterruptIn sw3(SW3);
SimonRez 2:52b3c0b95388 12
vsluiter 0:c8f15874531b 13 MODSERIAL pc(USBTX, USBRX);
vsluiter 0:c8f15874531b 14
SimonRez 2:52b3c0b95388 15 volatile char c;
SimonRez 2:52b3c0b95388 16 volatile char color;
SimonRez 2:52b3c0b95388 17
SimonRez 4:651d06e860e7 18 void Buttonpress()
SimonRez 2:52b3c0b95388 19 {
SimonRez 2:52b3c0b95388 20 if (c == 'r')
SimonRez 2:52b3c0b95388 21 {
SimonRez 2:52b3c0b95388 22 color = 'r';
SimonRez 2:52b3c0b95388 23 }
SimonRez 2:52b3c0b95388 24 else if (c == 'g')
SimonRez 2:52b3c0b95388 25 {
SimonRez 2:52b3c0b95388 26 color = 'g';
SimonRez 2:52b3c0b95388 27 }
SimonRez 2:52b3c0b95388 28 else if (c == 'b')
SimonRez 2:52b3c0b95388 29 {
SimonRez 2:52b3c0b95388 30 color = 'b';
SimonRez 2:52b3c0b95388 31 }
SimonRez 3:40a25c2c24ba 32 else if (c == NULL)
SimonRez 3:40a25c2c24ba 33 {
SimonRez 3:40a25c2c24ba 34 ledr = 1;
SimonRez 3:40a25c2c24ba 35 ledg = 1;
SimonRez 3:40a25c2c24ba 36 ledb = 1;
SimonRez 3:40a25c2c24ba 37 }
SimonRez 2:52b3c0b95388 38 else
SimonRez 2:52b3c0b95388 39 {
SimonRez 2:52b3c0b95388 40 pc.printf("Character %c is not valid \r\n",c);
SimonRez 2:52b3c0b95388 41 c = color;
SimonRez 3:40a25c2c24ba 42
SimonRez 3:40a25c2c24ba 43 ledr = 0;
SimonRez 3:40a25c2c24ba 44 ledg = 0;
SimonRez 3:40a25c2c24ba 45 ledb = 0;
SimonRez 3:40a25c2c24ba 46 wait(0.1f);
SimonRez 3:40a25c2c24ba 47 ledr = 1;
SimonRez 3:40a25c2c24ba 48 ledg = 1;
SimonRez 3:40a25c2c24ba 49 ledb = 1;
SimonRez 3:40a25c2c24ba 50 wait(0.1f);
SimonRez 3:40a25c2c24ba 51 ledr = 0;
SimonRez 3:40a25c2c24ba 52 ledg = 0;
SimonRez 3:40a25c2c24ba 53 ledb = 0;
SimonRez 3:40a25c2c24ba 54 wait(0.1f);
SimonRez 3:40a25c2c24ba 55 ledr = 1;
SimonRez 3:40a25c2c24ba 56 ledg = 1;
SimonRez 3:40a25c2c24ba 57 ledb = 1;
SimonRez 3:40a25c2c24ba 58 wait(0.1f);
SimonRez 3:40a25c2c24ba 59 ledr = 0;
SimonRez 3:40a25c2c24ba 60 ledg = 0;
SimonRez 3:40a25c2c24ba 61 ledb = 0;
SimonRez 3:40a25c2c24ba 62 wait(0.1f);
SimonRez 3:40a25c2c24ba 63 ledr = 1;
SimonRez 3:40a25c2c24ba 64 ledg = 1;
SimonRez 3:40a25c2c24ba 65 ledb = 1;
SimonRez 3:40a25c2c24ba 66 wait(0.1f);
SimonRez 2:52b3c0b95388 67 }
SimonRez 2:52b3c0b95388 68
SimonRez 2:52b3c0b95388 69 if (color == 'r')
SimonRez 2:52b3c0b95388 70 {
SimonRez 2:52b3c0b95388 71 ledr = !ledr;
SimonRez 2:52b3c0b95388 72 ledg = 1;
SimonRez 2:52b3c0b95388 73 ledb = 1;
SimonRez 2:52b3c0b95388 74 }
SimonRez 2:52b3c0b95388 75 else if (color == 'g')
SimonRez 2:52b3c0b95388 76 {
SimonRez 2:52b3c0b95388 77 ledr = 1;
SimonRez 2:52b3c0b95388 78 ledg = !ledg;
SimonRez 2:52b3c0b95388 79 ledb = 1;
SimonRez 2:52b3c0b95388 80 }
SimonRez 2:52b3c0b95388 81 else if (color == 'b')
SimonRez 2:52b3c0b95388 82 {
SimonRez 2:52b3c0b95388 83 ledr = 1;
SimonRez 2:52b3c0b95388 84 ledg = 1;
SimonRez 2:52b3c0b95388 85 ledb = !ledb;
SimonRez 2:52b3c0b95388 86 }
SimonRez 4:651d06e860e7 87
SimonRez 2:52b3c0b95388 88 wait(0.25f);
SimonRez 2:52b3c0b95388 89 ledr = 1;
SimonRez 2:52b3c0b95388 90 ledg = 1;
SimonRez 2:52b3c0b95388 91 ledb = 1;
SimonRez 2:52b3c0b95388 92
SimonRez 2:52b3c0b95388 93 }
SimonRez 2:52b3c0b95388 94
SimonRez 4:651d06e860e7 95 void CurrentColor()
SimonRez 4:651d06e860e7 96 {
SimonRez 4:651d06e860e7 97 if (color == 'r')
SimonRez 4:651d06e860e7 98 {
SimonRez 4:651d06e860e7 99 pc.printf("The current blinking color is: red. \r\n");
SimonRez 4:651d06e860e7 100 }
SimonRez 4:651d06e860e7 101 else if (color == 'g')
SimonRez 4:651d06e860e7 102 {
SimonRez 4:651d06e860e7 103 pc.printf("The current blinking color is: green. \r\n");
SimonRez 4:651d06e860e7 104 }
SimonRez 4:651d06e860e7 105 else if (color == 'b')
SimonRez 4:651d06e860e7 106 {
SimonRez 4:651d06e860e7 107 pc.printf("The current blinking color is: blue. \r\n");
SimonRez 4:651d06e860e7 108 }
SimonRez 4:651d06e860e7 109 else
SimonRez 4:651d06e860e7 110 {
SimonRez 4:651d06e860e7 111 pc.printf("The LED is currently not blinking.\r\n");
SimonRez 4:651d06e860e7 112 }
SimonRez 4:651d06e860e7 113 }
SimonRez 4:651d06e860e7 114
SimonRez 4:651d06e860e7 115 void LEDOFF()
SimonRez 4:651d06e860e7 116 {
SimonRez 4:651d06e860e7 117 color = NULL;
SimonRez 4:651d06e860e7 118 c = NULL;
SimonRez 4:651d06e860e7 119
SimonRez 4:651d06e860e7 120 ledr = 1;
SimonRez 4:651d06e860e7 121 ledg = 1;
SimonRez 4:651d06e860e7 122 ledb = 1;
SimonRez 4:651d06e860e7 123 }
SimonRez 4:651d06e860e7 124
vsluiter 0:c8f15874531b 125 int main()
vsluiter 0:c8f15874531b 126 {
SimonRez 2:52b3c0b95388 127 ledr = 1;
SimonRez 2:52b3c0b95388 128 ledg = 1;
SimonRez 2:52b3c0b95388 129 ledb = 1;
SimonRez 2:52b3c0b95388 130
SimonRez 4:651d06e860e7 131 pc.printf("\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n ~~~A$$De$troyer69~~~ \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n");
SimonRez 2:52b3c0b95388 132
vsluiter 0:c8f15874531b 133 pc.baud(115200);
SimonRez 4:651d06e860e7 134 Blinker.attach(Buttonpress, 0.5);
SimonRez 4:651d06e860e7 135 sw2.fall(CurrentColor);
SimonRez 4:651d06e860e7 136 sw3.rise(LEDOFF);
vsluiter 0:c8f15874531b 137
SimonRez 2:52b3c0b95388 138
SimonRez 2:52b3c0b95388 139 while (true)
SimonRez 2:52b3c0b95388 140 {
SimonRez 2:52b3c0b95388 141 c = pc.getc();
SimonRez 3:40a25c2c24ba 142
vsluiter 0:c8f15874531b 143 }
SimonRez 2:52b3c0b95388 144
vsluiter 0:c8f15874531b 145 }
SimonRez 2:52b3c0b95388 146
SimonRez 2:52b3c0b95388 147