読者です 読者をやめる 読者になる 読者になる

11/8/2016

そういえば、明日のロボ実験

圧力センサ読み込みプログラム

f:id:marthkapple3america:20161109201300p:plain

// serial_voltage_byte_sample1


const int led_pin = 9;

const int vol_pin = 1;


int vol_value = 0;


void setup() {

  Serial.begin( 9600 );

}


void loop() {

  vol_value = analogRead( vol_pin );


  analogWrite( led_pin, vol_value/4 );


  Serial.println(vol_value); //



  delay( 50 );

}


mmcについて


無線でモーター回すことに成功。最初arduinoに直接モーターをつなぎ、digitalWrite かanalogWrite で回そうとした。モーターにHIGH5V厳しいかなと思い、analogWriteで3.3Vぐらいの電圧で調整して出力させたが、信号きた後、モーターがピーという音鳴らすだけでビクともしない。HIGHは信号きて、ピーという音もならない。ここで、発想変えて電力の供給問題かなにかがあった事を思い出し、モータードライバを使用してモーターに信号が来た後、電圧を出力させてみた。成功!!!!

  

無線でリモコン信号(上から一個目と二個目のボタン)がきたらモーター回すプログラム


/*
 * IRremote: IRrecvDump - dump details of IR codes with IRrecv
 * An IR detector/demodulator must be connected to the input RECV_PIN.
 * Version 0.1 July, 2009
 * Copyright 2009 Ken Shirriff
 * JVC and Panasonic protocol added by Kristian Lauszus (Thanks to zenwheel and other people at the original blog post)
 * LG added by Darryl Smith (based on the JVC protocol)
 */

#include <IRremote.h>

/* 
*  Default is Arduino pin D11. 
*  You can change this to another available Arduino Pin.
*  Your IR receiver should be connected to the pin defined here
*/
int leftP   = 9;
int rightP  = 10;
int RECV_PIN = 11; 
long int TRIG_VAL = 0x8F71BE4;
long int GIRT_VAL = 0x8F71FE0;
IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
 pinMode(leftP, OUTPUT);
 pinMode(rightP, OUTPUT);
}


void dump(decode_results *results) {
  // Dumps out the decode_results structure.
  // Call this after IRrecv::decode()
  int count = results->rawlen;
  if (results->decode_type == UNKNOWN) {
    Serial.print("Unknown encoding: ");
  }
  else if (results->decode_type == NEC) {
    Serial.print("Decoded NEC: ");

  }
  else if (results->decode_type == SONY) {
    Serial.print("Decoded SONY: ");
  }
  else if (results->decode_type == RC5) {
    Serial.print("Decoded RC5: ");
  }
  else if (results->decode_type == RC6) {
    Serial.print("Decoded RC6: ");
  }
  else if (results->decode_type == PANASONIC) {
    Serial.print("Decoded PANASONIC - Address: ");
    Serial.print(results->address, HEX);
    Serial.print(" Value: ");
  }
  else if (results->decode_type == LG) {
    Serial.print("Decoded LG: ");
  }
  else if (results->decode_type == JVC) {
    Serial.print("Decoded JVC: ");
  }
  else if (results->decode_type == AIWA_RC_T501) {
    Serial.print("Decoded AIWA RC T501: ");
  }
  else if (results->decode_type == WHYNTER) {
    Serial.print("Decoded Whynter: ");
  }
  Serial.print(results->value, HEX);
  Serial.print(" (");
  Serial.print(results->bits, DEC);
  Serial.println(" bits)");
  Serial.print("Raw (");
  Serial.print(count, DEC);
  Serial.print("): ");

  for (int i = 1; i < count; i++) {
    if (i & 1) {
      Serial.print(results->rawbuf[i]*USECPERTICK, DEC);
    }
    else {
      Serial.write('-');
      Serial.print*1 {
    Serial.println(results.value, HEX);
    dump(&results);
     if(results.value == TRIG_VAL) {
         digitalWrite(rightP, LOW);
         digitalWrite(leftP, HIGH);
         delay(1000);
         digitalWrite(rightP, LOW);
         digitalWrite(leftP, LOW);
         delay(1000);
        }
        if(results.value == GIRT_VAL) {
         digitalWrite(rightP, HIGH);
         digitalWrite(leftP, LOW);
         delay(1000);
         digitalWrite(rightP, LOW);
         digitalWrite(leftP, LOW);
         delay(1000);
        }
    irrecv.resume(); // Receive the next value
  }
}

f:id:marthkapple3america:20161109102953j:plain


*1:unsigned long) results->rawbuf[i]*USECPERTICK, DEC);

    }
    Serial.print(" ");
  }
  Serial.println();
}

void loop() {
  if (irrecv.decode(&results