четверг, 7 февраля 2013 г.

ардуино программирование учебник

This means that whichever way you connect the bi-colour package to the supply, one PN junction will be forward-biased and emitting light, while the other remains off. To control both colours from an Arduino, we wire up the two package terminals between digital pins 10 and 11 of the board (as opposed to how you would connect an ordinary LED - between the ground pin and an output pin). Use a series 270 ohm resistance with the bi-colour LED; it doesn t matter which side it goes on.

Bi-colour LEDs are actually two LEDs, which are wired in an inverse parallel setup, and combined into one package with 2 leads.

P PPPPPP PP case '0' :P PPPPPPP P {P P PPPPPP P PP /* If the received character is '0', this block will be executed */P P P P PPP P P Serial.println(receivedCommand);P P P P P P P P /* Echoes the received character just to show a successful read. */P P P P P P P P svServo.writeMicrosecondsPPPPPPPPPPPPPP P PP (armaturePositionMatrix[0]);P P P P P P PPP /* Writes the corresponding position to the servo. */P P P P P P PP PPPPPPPPPPPPPPP break;PPPPPPPPPPPPPPP /* Exits the switch-case block. */P PPPPPPPPP }P PPPPPPPPP case '1' :P PPPPPPPPP {P P PPPPPPP P P Serial.println(receivedCommand);P P P P PP P PP svServo.writeMicrosecondsPPPPPPPPPPPPP P PPP (armaturePositionMatrix[1]);P P P P PPP PPP break;P PPPPPPPPP }P PPPPPPPPP case '2' :P PPPPPPPPP {P P PPPPPPP P P Serial.println(receivedCommand);P P P P P P P P svServo.writeMicrosecondsPPPPPPPPPPPPP P PPP (armaturePositionMatrix[2]);P P PPPPPPPPPPP break;P PPPPPPPPP }P PPPPPPPPP case '3' :P PPPPPPPPP {P P P PPPPPPP P P Serial.println(receivedCommand);P P P P PPP P P svServo.writeMicrosecondsPPPPPPPPPPPPP P PPP (armaturePositionMatrix[3]);P P PPPPPPPPPPP break;P PPPPPPPPP }P P P P PPP case '4' :P PPPPPPPPP {P P PPPPPPP P P Serial.println(receivedCommand);P P P P P P P P svServo.writeMicrosecondsPPPPPPPPPPPPP P PPP (armaturePositionMatrix[4]);P P PPPPPPPPPPP break;P P P PP PP }P PP PP }PPP }}

/* Servo Experiment Arunkumar M January 18, 2011 Send 0-4 via serial to turn the servo.*/#include <Servo.h>Servo svServo; /* Creates a Servo object named svServo*/char receivedCommand = 'x';int armaturePositionMatrix[] = {700, 1200, 1500, 2000, 2300};/* Declares an array holding various armature positions. If your servo starts grinding when you try 0 or 4, change this array to hold values in the range 1000 - 2000. */void setup(){PPP Serial.begin(9600);PPP svServo.attach(9);PPP svServo.writeMicroseconds(armaturePositionMatrix[0]);PPP /* Attaches the servo to pin 9 and sets the servo at position 0. */}void loop(){PPP if(Serial.available())PPP {P PPPPP receivedCommand = Serial.read();P PPPPP /* If any data is available in the serial interface buffer, it's read into receivedCommand. Reading the buffer automatically empties it of the read character. */PPPPPPP switch(receivedCommand)P PPPPP {P PPPPP P P /* This switch-case construct will evaluate the received character and write the corresponding position to the servo. */P

Comments are placed below the lines they refer to.

Also, please note that you can no longer use analogWrite() PWM functions on pins 9 and 10 if you’re using the Servo.h library (except on the Arduino Mega).

If you send the numerals 0, 1, 2, 3, 4 to the board, it will rotate the connected servo on pin 9 to various positions. Most servos swing 0-180 degrees over the corresponding argument range 700-2300 for the servoObject.writeMicroseconds()Pfunction.

Arduino: Serial Servo Control Code Here’s a dead-simple serial servo control code for Arduino and compatible boards!

Комментариев нет:

Отправить комментарий