サーボコントローラーを作ってみた。

適当設計なのですが、毎回サーボテストするのにブレッドボードでなんだかんだするのが面倒になってきたのでサーボテスト用の基板を1ボードに纏めてみました。ArduinoにスイッチとLED載せただけなんですが、なにげに結構便利です。ESCのテストもこれと電源で出来ちゃいます。

IMG_1209

■回路図
BrMoSig_v1_r1

■スケッチ

#include <stdio.h>
#include <Servo.h>

//Key message
char msgs[5][16] = {"SW No.1 : 1000 ",
"SW No.2 : 1250 ",
"SW No.3 : 1500 ",
"SW No.4 : 1750 ",
"SW No.5 : 2000 " };
int adc_key_val[5] ={30, 150, 360, 535, 750 };
int led_pin_val[5] ={4, 5, 6, 7, 13 };
static uint8_t NUM_KEYS = 5;
int adc_key_in;
int key=-1;
static uint8_t oldkey=-1;

Servo myservo; // create servo object to control a servo

void setup() {
// Setup Serial
Serial.begin(19200);

for (int i=0;i<5;i++){
pinMode(led_pin_val[i], OUTPUT);
digitalWrite(led_pin_val[i], HIGH);
}

Serial.println("KEYPAD testing... pressing");

myservo.attach(8) ; // attaches the servo on pin 9 to the servo object
}

void loop() {

adc_key_in = analogRead(0); // read the value from the sensor

key = get_key(adc_key_in); // convert into key press

if (key != oldkey) // if keypress is detected
{
delay(50); // wait for debounce time
adc_key_in = analogRead(0); // read the value from the sensor
key = get_key(adc_key_in); // convert into key press
if (key != oldkey)
{
oldkey = key;
if (key >=0)
{
Serial.println(msgs[key]);

myservo.write(key*250+1000);
for (int i=0;i<5;i++){
digitalWrite(led_pin_val[i], HIGH);
}
digitalWrite(led_pin_val[key], LOW);
}
}
}

delay(200);
}

// Convert ADC value to key number
int get_key(unsigned int input){
int k;

for (k = 0; k < NUM_KEYS; k++){
if (input < adc_key_val[k]){
return k;
}
}

if (k >= NUM_KEYS) k = -1; // No valid key pressed
return k;
}

 

  1. コメントはまだありません。

  1. トラックバックはまだありません。


Warning: Undefined variable $user_ID in /home/r3087696/public_html/blog.eldhrimnir.com/wp-content/themes/monochrome/comments.php on line 172

Fatal error: Uncaught Error: Undefined constant "cs_print_smilies" in /home/r3087696/public_html/blog.eldhrimnir.com/wp-content/themes/monochrome/comments.php:185 Stack trace: #0 /home/r3087696/public_html/blog.eldhrimnir.com/wp-includes/comment-template.php(1617): require() #1 /home/r3087696/public_html/blog.eldhrimnir.com/wp-content/themes/monochrome/single.php(57): comments_template() #2 /home/r3087696/public_html/blog.eldhrimnir.com/wp-includes/template-loader.php(106): include('/home/r3087696/...') #3 /home/r3087696/public_html/blog.eldhrimnir.com/wp-blog-header.php(19): require_once('/home/r3087696/...') #4 /home/r3087696/public_html/blog.eldhrimnir.com/index.php(17): require('/home/r3087696/...') #5 {main} thrown in /home/r3087696/public_html/blog.eldhrimnir.com/wp-content/themes/monochrome/comments.php on line 185