RGB

Dependencies:   mbed

Fork of RGB-15 by Ladner-Praja

Committer:
ladner
Date:
Tue Jul 07 21:17:00 2015 +0000
Revision:
8:c82246829dd4
Parent:
7:936bef387bbd
Child:
9:6ce73c996e33
Folge der Linie(2015);

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ladner 0:cce97dfa8e6b 1 #include "mbed.h"
ladner 0:cce97dfa8e6b 2
ladner 0:cce97dfa8e6b 3 I2C i2c(p28, p27);
ladner 0:cce97dfa8e6b 4 BusOut myled(LED1,LED2,LED3,LED4);
ladner 0:cce97dfa8e6b 5 BusOut myrgb(P1_23,P1_25,P1_24);
ladner 0:cce97dfa8e6b 6 DigitalOut LedBlue(P1_28);
ladner 0:cce97dfa8e6b 7 BusIn myline(p18,p16,p19,p17);
ladner 0:cce97dfa8e6b 8 DigitalIn linecenter(p20);
ladner 0:cce97dfa8e6b 9 DigitalOut online(P1_6);
ladner 0:cce97dfa8e6b 10 DigitalOut MotorL_EN(P1_15);
ladner 0:cce97dfa8e6b 11 DigitalOut MotorL_FORWARD(P1_1);
ladner 0:cce97dfa8e6b 12 DigitalOut MotorL_REVERSE(P1_0);
ladner 0:cce97dfa8e6b 13 DigitalOut MotorR_EN(P0_21);
ladner 0:cce97dfa8e6b 14 DigitalOut MotorR_FORWARD(P1_3);
ladner 0:cce97dfa8e6b 15 DigitalOut MotorR_REVERSE(P1_4);
ladner 0:cce97dfa8e6b 16 DigitalOut Motor_SENSOR(P1_7);
ladner 0:cce97dfa8e6b 17 DigitalOut enable(P1_2);
ladner 0:cce97dfa8e6b 18 PwmOut mg1(P1_15);
ladner 0:cce97dfa8e6b 19 PwmOut mg2(P0_21);
ladner 0:cce97dfa8e6b 20 DigitalIn SensorL(P1_12);
ladner 0:cce97dfa8e6b 21 DigitalIn SensorR(P1_13);
ladner 0:cce97dfa8e6b 22 int data;
ladner 2:1317061163f8 23 int out_helper[8];
ladner 0:cce97dfa8e6b 24 int main()
ladner 0:cce97dfa8e6b 25 {
ladner 2:1317061163f8 26 out_helper[0]=0;
ladner 2:1317061163f8 27 out_helper[1]=1;
ladner 2:1317061163f8 28 out_helper[2]=3;
ladner 2:1317061163f8 29 out_helper[3]=7;
ladner 2:1317061163f8 30 out_helper[4]=15;
ladner 2:1317061163f8 31 out_helper[5]=14;
ladner 2:1317061163f8 32 out_helper[6]=12;
ladner 2:1317061163f8 33 out_helper[7]=8;
ladner 2:1317061163f8 34
ladner 0:cce97dfa8e6b 35 enable = 0;
ladner 0:cce97dfa8e6b 36 online = 0;
ladner 0:cce97dfa8e6b 37 Motor_SENSOR=0;
ladner 0:cce97dfa8e6b 38
ladner 0:cce97dfa8e6b 39 myrgb = 0x07;//7->aus
ladner 0:cce97dfa8e6b 40 LedBlue=1;
ladner 0:cce97dfa8e6b 41 myled = 0x00;
ladner 0:cce97dfa8e6b 42
ladner 0:cce97dfa8e6b 43 MotorL_EN = 0;
ladner 0:cce97dfa8e6b 44 MotorL_FORWARD = 0;
ladner 0:cce97dfa8e6b 45 MotorL_REVERSE = 0;
ladner 0:cce97dfa8e6b 46 MotorR_EN = 0;
ladner 0:cce97dfa8e6b 47 MotorR_FORWARD = 0;
ladner 0:cce97dfa8e6b 48 MotorR_REVERSE = 0;
ladner 0:cce97dfa8e6b 49 mg1=0.5;
ladner 0:cce97dfa8e6b 50 mg2=0.5;
ladner 0:cce97dfa8e6b 51
ladner 0:cce97dfa8e6b 52 i2c.start();
ladner 0:cce97dfa8e6b 53 i2c.write(0x40);
ladner 0:cce97dfa8e6b 54 i2c.write(0x06);
ladner 0:cce97dfa8e6b 55 i2c.write(0x00);
ladner 0:cce97dfa8e6b 56 i2c.stop();
ladner 0:cce97dfa8e6b 57
ladner 0:cce97dfa8e6b 58 i2c.start();
ladner 0:cce97dfa8e6b 59 i2c.write(0x40);
ladner 0:cce97dfa8e6b 60 i2c.write(0x02);
ladner 0:cce97dfa8e6b 61 i2c.write(~0x00);
ladner 0:cce97dfa8e6b 62 i2c.stop();
ladner 0:cce97dfa8e6b 63
ladner 1:28cfac75543f 64 int waiting = 0;
ladner 1:28cfac75543f 65 bool active = false;
ladner 1:28cfac75543f 66
ladner 0:cce97dfa8e6b 67 while(1){
ladner 0:cce97dfa8e6b 68 // Einlesen der Taster und speichern unter data
ladner 0:cce97dfa8e6b 69 i2c.start();
ladner 0:cce97dfa8e6b 70 i2c.write(0x40);
ladner 0:cce97dfa8e6b 71 i2c.write(0x01);
ladner 0:cce97dfa8e6b 72 i2c.start();
ladner 0:cce97dfa8e6b 73 i2c.write(0x41);
ladner 0:cce97dfa8e6b 74 data = i2c.read(0);
ladner 0:cce97dfa8e6b 75 i2c.stop();
ladner 1:28cfac75543f 76
ladner 1:28cfac75543f 77 if(active)
ladner 1:28cfac75543f 78 {
ladner 1:28cfac75543f 79 enable = 1;
ladner 1:28cfac75543f 80 online = 1;
ladner 3:2cd73b6f5b50 81 myrgb=3;
ladner 2:1317061163f8 82 wait(0.5);
ladner 1:28cfac75543f 83 }
ladner 1:28cfac75543f 84 else
ladner 1:28cfac75543f 85 {
ladner 2:1317061163f8 86 if(waiting<7)
ladner 5:e968c184ad9f 87 {
ladner 5:e968c184ad9f 88 wait(0.5);
ladner 5:e968c184ad9f 89 if(waiting==0)
ladner 5:e968c184ad9f 90 {
ladner 5:e968c184ad9f 91 enable = 0;
ladner 5:e968c184ad9f 92 online = 0;
ladner 5:e968c184ad9f 93 myrgb=7;
ladner 5:e968c184ad9f 94 }
ladner 1:28cfac75543f 95 waiting++;
ladner 5:e968c184ad9f 96 }
ladner 1:28cfac75543f 97 else
ladner 1:28cfac75543f 98 {
ladner 2:1317061163f8 99 enable = 1;
ladner 2:1317061163f8 100 online = 1;
ladner 5:e968c184ad9f 101 wait(0.5);
ladner 8:c82246829dd4 102 if((myline>=1)||(linecenter==1))
ladner 2:1317061163f8 103 {
ladner 7:936bef387bbd 104 active=true;
ladner 2:1317061163f8 105 myrgb=6;
ladner 7:936bef387bbd 106 myled=0;
ladner 7:936bef387bbd 107 wait(0.5);
ladner 2:1317061163f8 108 }
ladner 2:1317061163f8 109 else
ladner 3:2cd73b6f5b50 110 myrgb=4;
ladner 2:1317061163f8 111 waiting=0;
ladner 1:28cfac75543f 112 }
ladner 2:1317061163f8 113 myled=out_helper[waiting];
ladner 1:28cfac75543f 114 }
ladner 2:1317061163f8 115 //0=>keine Linie
ladner 0:cce97dfa8e6b 116
ladner 0:cce97dfa8e6b 117 //01->forneMitte
ladner 0:cce97dfa8e6b 118 //02->hintenMitte
ladner 0:cce97dfa8e6b 119 //04->forneLinks
ladner 0:cce97dfa8e6b 120 //08->forneRects
ladner 0:cce97dfa8e6b 121 //10->hintenLinks
ladner 0:cce97dfa8e6b 122 //20->hintenRechts
ladner 0:cce97dfa8e6b 123 //40->Rechts
ladner 0:cce97dfa8e6b 124 //80->Links
ladner 0:cce97dfa8e6b 125
ladner 0:cce97dfa8e6b 126 }
ladner 0:cce97dfa8e6b 127 }