Naoya Hasegawa / Mbed 2 deprecated Kore_test13

Dependencies:   USBDevice mbed

Committer:
hase
Date:
Wed Nov 07 09:35:47 2012 +0000
Revision:
0:7db0d1b1daf0
test pwm ng

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hase 0:7db0d1b1daf0 1 #include "mbed.h"
hase 0:7db0d1b1daf0 2 #include <PwmOut.h>
hase 0:7db0d1b1daf0 3 //#include "USBSerial.h"
hase 0:7db0d1b1daf0 4
hase 0:7db0d1b1daf0 5
hase 0:7db0d1b1daf0 6
hase 0:7db0d1b1daf0 7 AnalogIn ana0(P0_11);
hase 0:7db0d1b1daf0 8 AnalogIn ana1(P0_12);
hase 0:7db0d1b1daf0 9
hase 0:7db0d1b1daf0 10 DigitalOut myled0(P1_31);
hase 0:7db0d1b1daf0 11 DigitalOut myled1(P1_23);
hase 0:7db0d1b1daf0 12
hase 0:7db0d1b1daf0 13 //DigitalOut po_0(P0_20);//3:
hase 0:7db0d1b1daf0 14 //DigitalOut po_1(P0_18);//pwm0
hase 0:7db0d1b1daf0 15 //DigitalOut po_1(p24);//pwm0
hase 0:7db0d1b1daf0 16 //DigitalOut po_2(P1_15);
hase 0:7db0d1b1daf0 17 DigitalOut po_3(P0_19);//pwm1
hase 0:7db0d1b1daf0 18 //DigitalOut po_4(P1_24);//pwm2
hase 0:7db0d1b1daf0 19 //DigitalOut po_5(P1_16);
hase 0:7db0d1b1daf0 20
hase 0:7db0d1b1daf0 21 //DigitalOut po_6(P0_7);
hase 0:7db0d1b1daf0 22 //DigitalOut po_7(P1_25);//pwm3
hase 0:7db0d1b1daf0 23 DigitalOut po_8(P1_26);//pwm4
hase 0:7db0d1b1daf0 24 DigitalOut po_9(P1_27);//pwm5
hase 0:7db0d1b1daf0 25 //DigitalOut po_10(P0_8);//miso0
hase 0:7db0d1b1daf0 26 DigitalOut po_11(P0_10);//mosi
hase 0:7db0d1b1daf0 27
hase 0:7db0d1b1daf0 28 DigitalOut myled_R(P1_15);
hase 0:7db0d1b1daf0 29 DigitalOut myled_G(P1_27);//0_8
hase 0:7db0d1b1daf0 30 DigitalOut myled_B(P0_20);//0_20
hase 0:7db0d1b1daf0 31
hase 0:7db0d1b1daf0 32
hase 0:7db0d1b1daf0 33 unsigned int Red;
hase 0:7db0d1b1daf0 34 unsigned int Green;
hase 0:7db0d1b1daf0 35 unsigned int Blue;
hase 0:7db0d1b1daf0 36 unsigned int Motor;
hase 0:7db0d1b1daf0 37
hase 0:7db0d1b1daf0 38 Ticker flipper;
hase 0:7db0d1b1daf0 39 PwmOut motor2(P1_24);
hase 0:7db0d1b1daf0 40 DigitalOut mr2(P1_16);
hase 0:7db0d1b1daf0 41
hase 0:7db0d1b1daf0 42 PwmOut motor3(P1_25);
hase 0:7db0d1b1daf0 43 DigitalOut mr3(P0_7);
hase 0:7db0d1b1daf0 44
hase 0:7db0d1b1daf0 45 PwmOut motor4(P1_26);
hase 0:7db0d1b1daf0 46 DigitalOut mr4(P0_8);
hase 0:7db0d1b1daf0 47
hase 0:7db0d1b1daf0 48 DigitalOut mr6(P1_20);
hase 0:7db0d1b1daf0 49
hase 0:7db0d1b1daf0 50 //PwmOut motor0(P0_18);
hase 0:7db0d1b1daf0 51 //DigitalOut mr4(P0_8);
hase 0:7db0d1b1daf0 52
hase 0:7db0d1b1daf0 53 //USBSerial serial;
hase 0:7db0d1b1daf0 54
hase 0:7db0d1b1daf0 55 void flip() {
hase 0:7db0d1b1daf0 56 static int i;
hase 0:7db0d1b1daf0 57
hase 0:7db0d1b1daf0 58 myled0 = ~myled0;
hase 0:7db0d1b1daf0 59
hase 0:7db0d1b1daf0 60 if(i>Red)myled_R = 1;
hase 0:7db0d1b1daf0 61 else myled_R = 0;
hase 0:7db0d1b1daf0 62
hase 0:7db0d1b1daf0 63 if(i>Green)myled_G = 1;
hase 0:7db0d1b1daf0 64 else myled_G = 0;
hase 0:7db0d1b1daf0 65
hase 0:7db0d1b1daf0 66 if(i>Blue)myled_B = 1;
hase 0:7db0d1b1daf0 67 else myled_B = 0;
hase 0:7db0d1b1daf0 68
hase 0:7db0d1b1daf0 69
hase 0:7db0d1b1daf0 70
hase 0:7db0d1b1daf0 71
hase 0:7db0d1b1daf0 72 i++;
hase 0:7db0d1b1daf0 73 if(i>256){
hase 0:7db0d1b1daf0 74 i = 0;
hase 0:7db0d1b1daf0 75 }
hase 0:7db0d1b1daf0 76
hase 0:7db0d1b1daf0 77 }
hase 0:7db0d1b1daf0 78
hase 0:7db0d1b1daf0 79 int main() {
hase 0:7db0d1b1daf0 80 float Mot_Pot;
hase 0:7db0d1b1daf0 81 float Master;
hase 0:7db0d1b1daf0 82 // PwmOut* motor0;
hase 0:7db0d1b1daf0 83
hase 0:7db0d1b1daf0 84 PwmOut motor0(P0_18);
hase 0:7db0d1b1daf0 85
hase 0:7db0d1b1daf0 86
hase 0:7db0d1b1daf0 87 LPC_IOCON->PIO0_18 &= ~0x07;
hase 0:7db0d1b1daf0 88 LPC_IOCON->PIO0_18 |= 0x02;
hase 0:7db0d1b1daf0 89 LPC_IOCON->PIO0_19 &= ~0x07;
hase 0:7db0d1b1daf0 90 LPC_IOCON->PIO0_19 |= 0x02;
hase 0:7db0d1b1daf0 91
hase 0:7db0d1b1daf0 92 flipper.attach(&flip, 0.00005); // the address of the function to be attached (flip) and the interval (2 seconds)
hase 0:7db0d1b1daf0 93 // flipper2.attach(&flip2, 0.0005); // the address of the function to be attached (flip) and the interval (2 seconds)
hase 0:7db0d1b1daf0 94 // flipper.attach(&flip, 0.0001); // the address of the function to be attached (flip) and the interval (2 seconds)
hase 0:7db0d1b1daf0 95
hase 0:7db0d1b1daf0 96 motor0.period(0.002);
hase 0:7db0d1b1daf0 97 // motor2.period(0.02);
hase 0:7db0d1b1daf0 98 // motor3.period(0.02);
hase 0:7db0d1b1daf0 99 // motor4.period(0.02);
hase 0:7db0d1b1daf0 100
hase 0:7db0d1b1daf0 101
hase 0:7db0d1b1daf0 102 Red = 0;
hase 0:7db0d1b1daf0 103 Green = 0;
hase 0:7db0d1b1daf0 104 Blue = 0;
hase 0:7db0d1b1daf0 105
hase 0:7db0d1b1daf0 106 myled0 = 0;
hase 0:7db0d1b1daf0 107
hase 0:7db0d1b1daf0 108 mr2 = 0;
hase 0:7db0d1b1daf0 109 mr3 = 0;
hase 0:7db0d1b1daf0 110 mr4 = 0;
hase 0:7db0d1b1daf0 111
hase 0:7db0d1b1daf0 112 LPC_IOCON->PIO1_20 &= ~0x07;
hase 0:7db0d1b1daf0 113 LPC_IOCON->PIO1_20 |= 0x00;
hase 0:7db0d1b1daf0 114
hase 0:7db0d1b1daf0 115 while(1) {
hase 0:7db0d1b1daf0 116
hase 0:7db0d1b1daf0 117 Mot_Pot = ana0;
hase 0:7db0d1b1daf0 118 Master = ana1;
hase 0:7db0d1b1daf0 119
hase 0:7db0d1b1daf0 120 Red = (int)(Master * 256);
hase 0:7db0d1b1daf0 121 Green = (int)(Master * 256);
hase 0:7db0d1b1daf0 122 Blue = (int)(Master * 256);
hase 0:7db0d1b1daf0 123
hase 0:7db0d1b1daf0 124 motor0.write(0.5);
hase 0:7db0d1b1daf0 125 motor2 = Master;
hase 0:7db0d1b1daf0 126 motor3 = Master;
hase 0:7db0d1b1daf0 127 motor4 = Master;
hase 0:7db0d1b1daf0 128
hase 0:7db0d1b1daf0 129 mr2 = 0;
hase 0:7db0d1b1daf0 130 mr3 = 0;
hase 0:7db0d1b1daf0 131 mr4 = 0;
hase 0:7db0d1b1daf0 132 mr6 = !mr6;
hase 0:7db0d1b1daf0 133 /*
hase 0:7db0d1b1daf0 134 mr2 = !mr2;
hase 0:7db0d1b1daf0 135 mr3 = !mr3;
hase 0:7db0d1b1daf0 136 mr4 = !mr4;
hase 0:7db0d1b1daf0 137 mr6 = !mr6;
hase 0:7db0d1b1daf0 138
hase 0:7db0d1b1daf0 139 serial.puts("\x1b[3;1H");
hase 0:7db0d1b1daf0 140 // serial.printf("Mot_Pot = %f \r\n",Mot_Pot);
hase 0:7db0d1b1daf0 141 serial.printf("Masetr = %f \r\n",Master);
hase 0:7db0d1b1daf0 142
hase 0:7db0d1b1daf0 143 serial.printf("Red = %d \r\n",Red);
hase 0:7db0d1b1daf0 144 serial.printf("Green = %d \r\n",Green);
hase 0:7db0d1b1daf0 145 serial.printf("Blue = %d \r\n",Blue);
hase 0:7db0d1b1daf0 146 */
hase 0:7db0d1b1daf0 147 }
hase 0:7db0d1b1daf0 148 }