Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: EthernetNetIf mbed
Fork of Monitor0 by
Diff: main.cpp
- Revision:
- 1:be04a186a221
- Parent:
- 0:72d0d2736b7f
- Child:
- 2:0ea44fca1a81
diff -r 72d0d2736b7f -r be04a186a221 main.cpp
--- a/main.cpp Tue Jun 26 06:24:23 2012 +0000
+++ b/main.cpp Sun Jul 29 15:27:18 2012 +0000
@@ -13,8 +13,13 @@
//EthernetNetIf eth;
UDPSocket udp;
-DigitalOut int_led(LED1);
-DigitalOut P15(p15);
+DigitalOut int_led1(LED1);
+DigitalOut int_led2(LED2);
+DigitalOut int_led3(LED3);
+DigitalOut int_led4(LED4);
+DigitalOut P21(p21);
+DigitalOut P22(p22);
+DigitalOut P23(p23);
Serial pc(USBTX,USBRX);
Host multicast(IpAddr(192,168,1,10),27200, NULL); //Target IP and port
ADC adc(SAMPLE_RATE, 1);
@@ -33,16 +38,30 @@
char str[50];
unsigned char buf[10];
int count_puls;
+int device_no;
int led1_on = 0;
void Timer_Handler()
{
if(count_puls) {
- printf("cp %d\n", count_puls);
+// printf("cp %d\n", count_puls);
count_puls--;
led1_on = !led1_on;
- int_led = led1_on;
- P15 = !led1_on;
- timeout.attach_us(Timer_Handler, 100);
+ // int_led1 = led1_on;
+ switch(device_no) {
+ case 1:
+ P21 = !led1_on;
+ break;
+ case 2:
+ P22 = !led1_on;
+ break;
+ case 3:
+ P23 = !led1_on;
+ break;
+ default:
+ timeout.detach();
+ return;
+ }
+ timeout.attach_us(Timer_Handler, 1000);
} else
timeout.detach();
}
@@ -55,41 +74,75 @@
while ( int len = udp.recvfrom( buf, 63, &host ) ) {
if ( len <= 0 )
break;
- printf("From %d.%d.%d.%d: %s\n", host.getIp()[0], host.getIp()[1], host.getIp()[2], host.getIp()[3], buf);
+ // printf("From %d.%d.%d.%d: %s\n", host.getIp()[0], host.getIp()[1], host.getIp()[2], host.getIp()[3], buf);
}
switch(buf[0]) {
case '1':
- count_puls = 8;
+ device_no = 1;
+ int_led1 = 1;
break;
case '2':
- count_puls = 4;
+ device_no = 2;
+// int_led2 = 1;
break;
case '3':
- count_puls = 6;
+ device_no = 3;
+// int_led3 = 1;
+ break;
+ default:
+ device_no = 0;
+// int_led4 = 1;
+ count_puls = 0;
+ return;
+ }
+ int_led1 = 0;
+ int_led2 = 0;
+ int_led3 = 0;
+ int_led4 = 0;
+ switch(buf[1]) {
+ case '1':
+ count_puls = 2; //8
+ // int_led1 = 1;
+ break;
+ case '2':
+ count_puls = 8; //4;
+ // int_led2 = 1;
+ break;
+ case '3':
+ count_puls = 4; //6;
+ // int_led3 = 1;
break;
case '4':
- count_puls = 2;
- break;
+ count_puls = 6; //2;8
+ // int_led4 = 1;
+ break;
case '5':
count_puls = 10;
- break;
+ // int_led1 = 1;
+ // int_led2 = 1;
+ break;
default:
count_puls = 0;
- }
- timeout.attach_us(Timer_Handler, 100);
+ }
+ timeout.attach_us(Timer_Handler, 1000);
break;
}
}
-/*
- void adc_comlete(uint32_t value) {
- samples1 = adc.read(p20);
- Net::poll(); //Do network stuff
- sprintf(str, "1=%4u\0", samples1);
- printf("%d\n", samples1);
- udp.sendto( str, strlen(str)+1, &multicast );
+
+void adc_comlete(uint32_t value) {
+// void adc_comlete() {
+ int_led1 = 1;
+ int_led2 = 1;
+ int_led3 = 1;
+ int_led4 = 1;
+ // samples1 = adc.read(p20);
+ // Net::poll(); //Do network stuff
+ // sprintf(str, "1=%4u\0", samples1);
+ // printf("%d\n", samples1);
+ // udp.sendto( str, strlen(str)+1, &multicast );
}
-*/
+
unsigned short Major(unsigned short dadc2, unsigned short dadc0, unsigned short dadc1)
{
//printf("%d %d %d\n", dadc2, dadc0, dadc1);
@@ -178,7 +231,7 @@
pc.baud(57600);
//Ethernet initializing, Serial Interface - 57600 kbit/s
printf("Setting up...\n");
- P15 = 1;
+ P21 = P22 = P23 = 1;
EthernetErr ethErr = eth.setup();
if (ethErr) {
// printf("Error %d in setup.\n", ethErr);
@@ -208,7 +261,7 @@
//Turning ON Burst-mode ADC on pins 17,18,19,20 note: connect not used ADC ping to ground
// adc.startmode(0,0);
- adc.burst(1);
+ adc.burst(1);
adc.setup(p20,1);
adc.setup(p19,1);
// adc.select(p20);
@@ -219,6 +272,8 @@
// printf("%d\n", adc.channel_to_pin_number(0));
flipper.attach_us(&flip, 83); // Interrupt Turn ON (100 - 10kHz; 1000 - 1 kHz)
+ adc.append(p19, adc_comlete);
+ adc.interrupt_state(p19, 1);
tri = 0;
while(1) {
tri = tri + 0.001;
