Bert Gereels / Mbed 2 deprecated ProjectOne

Dependencies:   C12832 LM75B mbed EthernetInterface mbed-rtos

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers selection.cpp Source File

selection.cpp

00001 #include "selection.h"
00002 #include "mbed.h"
00003 
00004 #pragma once
00005 
00006 
00007 namespace ProjectOne{
00008     
00009     Selection::Selection(PinName firstPin, PinName secondPin, PinName thirdPin, PinName fourthPin, PinName fifthPin)  : joy(firstPin,secondPin,thirdPin,fourthPin,fifthPin)
00010     {
00011 
00012     }
00013     
00014     string Selection::determineMode(void){
00015         printf("Select desired operating mode\r\n");
00016         printf("Confirm by pressing down joystick\r\n");
00017         printf("Up = master, Down = slave\r\n");
00018         string selected_mode = "";
00019         while(joy.read() != 1){
00020             if(joy.read() == 2){
00021                 selected_mode = "master";
00022                 printf("Current mode is: '%s'\r\n", selected_mode.c_str());
00023             }
00024             if(joy.read()  == 4){
00025                 selected_mode = "slave";
00026                 printf("Current mode is: '%s'\r\n", selected_mode.c_str());
00027             }
00028             wait(0.5);
00029         }
00030         if(joy.read() == 1){
00031             return selected_mode;
00032         }
00033     }
00034     
00035     int Selection::determineId(void){
00036         wait(1);
00037         int selected_id = 100;
00038         printf("Select desired id, range: 100-110, standard = 100\r\n");
00039         printf("Left = decrease, Right = increase\r\n");
00040         while(joy.read() != 1){
00041             if(joy.read()  == 8){
00042                 if(selected_id <= 110 && selected_id > 100){
00043                     selected_id--;
00044                     printf("Current id is: '%d'\r\n", selected_id);
00045                 } 
00046             }
00047             if(joy.read()  == 16){
00048                 if(selected_id >= 100 && selected_id < 110){
00049                     selected_id++;
00050                     printf("Current id is: '%d'\r\n", selected_id);
00051                 }
00052             }
00053             wait(0.5);
00054         }
00055         if(joy.read() == 1){
00056             return selected_id;
00057         } 
00058     }
00059     
00060 }