/*############################################################# Program Name : ex2_servo_multiple Author : Grant Phillips Date Modified : 14/01/2016 Compiler : ARMmbed Tested On : STM32F4-Discovery Description : Example program that changes the position of 2 servos at the the same time according to 8 switches. SW7 to SW4 controls servo1 and SW3 to SW0 controls servo2. Requirements : * STM32F4-Discovery Board Circuit : * Servo control signal connected to PA15 servo1 * Servo control signal connected to PB5 servo2 * 8 switches connected to PE8 - PE15 with pullup resitors ##############################################################*/ #include "mbed.h" DigitalIn SW0(PE_8); DigitalIn SW1(PE_9); DigitalIn SW2(PE_10); DigitalIn SW3(PE_11); DigitalIn SW4(PE_12); DigitalIn SW5(PE_13); DigitalIn SW6(PE_14); DigitalIn SW7(PE_15); PwmOut servo1(PA_15); //default period is 20ms (which is perfect for servos) PwmOut servo2(PB_5); int main() { while(1) { /*servo1*/ if(SW7 == 0) //remember the switches are inverse logic servo1.pulsewidth_us(2300); else if(SW6 == 0) servo1.pulsewidth_us(1800); else if(SW5 == 0) servo1.pulsewidth_us(1200); else if(SW4 == 0) servo1.pulsewidth_us(700); else servo1.pulsewidth_us(1500); /*servo2*/ if(SW3 == 0) servo2.pulsewidth_us(2300); else if(SW2 == 0) servo2.pulsewidth_us(1800); else if(SW1 == 0) servo2.pulsewidth_us(1200); else if(SW0 == 0) servo2.pulsewidth_us(700); else servo2.pulsewidth_us(1500); } }