Kirja   |  Artikkelit   |  Keskustelu   |  Tiedostot   |  Galleria
Hyönteisrobotti, kampanja.

12.5. tuntiraportti

@author Jero Kostiainen, Riikka Lindroos, Roope Kuikka

12.5.

Testasimme Parallax Servoa, johon löysimme sorsan Sulautetut-kirjasta. Koodi oli hyönteisrobotista servoRange.pde, joka pyöritti servoa myötäpäivään ja vastapäivään.

Kytkennät olivat simppelit. Servon datajohto yhdistettiin Arduinon digitalpin 2:een, ground groundiin ja virta +5V:een.

kytkentaKuva

sorsaa:

int servoFrontPin=2;

void pulseServo(int servoPin, int pulseLenUs)

{

    digitalWrite(servoPin, HIGH);

    delayMicroseconds(pulseLenUs);

    digitalWrite(servoPin, LOW);

    delay(20);

}

void setup()

{

    pinMode(servoFrontPin, OUTPUT);

    Serial.begin(115200);

}

void loop()

{

    for (int i=1; i<=3000; i=i+2) {

            pulseServo(servoFrontPin, i);

            Serial.println(i);  

    }

}

Saimme servon vaihtamaan suuntaa nopeasti edes ja takas Sulautetut-kirjasta löytyvällä moveServo.pde-koodilla:

int servoFrontPin=2;

void pulseServo(int servoPin, int pulseLenUs)

{

    digitalWrite(servoPin, HIGH);

    delayMicroseconds(pulseLenUs);

    digitalWrite(servoPin, LOW);

    delay(20);

}

void setup()

{

    pinMode(servoFrontPin, OUTPUT);

    Serial.begin(115200);

}

void loop()

{

    for (int i=0; i<=25; i++) {

            pulseServo(servoFrontPin, 1500);

    }

    for (int i=0; i<=25; i++) {

            pulseServo(servoFrontPin, 2400);

    }

    for (int i=0; i<=25; i++) {

            pulseServo(servoFrontPin, 1500);

    }

    for (int i=0; i<=25; i++) {

            pulseServo(servoFrontPin, 600);

    }

}

Testasimme myös Roopen (random-)summeria Arduinon example-sorsa blinkillä. Summeri soi yhtä kauniisti kuin ledi välkkyy. Kytkennät olivat ground ja digPin.

int summeriPin = 13;

void setup() {

pinMode(summeriPin, OUTPUT);
}

void loop()
{ digitalWrite(summeriPin, HIGH); delay(1000);
digitalWrite(summeriPin, LOW);
delay(1000);
}

Piezo-elementin testaus

Saimme digitalBlinkillä aluksi vain nakutustyyppistä ääntä, mutta delay:tä uudestaan määrittelemällä saimme erikorkuisia ääniä. Kytkennät olivat simppelit; ground ja digitalPin.

0
  |     |     |     |  

Comments

Post new comment

  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]".
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Every instance heading tags will be modified to include an id attribute for anchor linking.
  • Every instance of "<!--tableofcontents-->" in the input text will be replaced with a collapsible mediawiki-style table of contents. Accepts options for title, list style, minimum heading level, and maximum heading level as follows: <!--tableofcontents list: ol; title: Table of Contents; minlevel: 1; maxlevel: 3;-->. All arguments are optional and defaults are shown.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Image links with 'rel="lightbox"' in the <a> tag will appear in a Lightbox when clicked on.
  • Image links from G2 are formatted for use with Lightbox2
  • Image links with 'rel="lightshow"' in the <a> tag will appear in a Lightbox slideshow when clicked on.
  • Links to video content with 'rel="lightvideo"' in the <a> tag will appear in a Lightbox when clicked on.
  • Links to inline or modal content with 'rel="lightmodal"' in the <a> tag will appear in a Lightbox when clicked on.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters (without spaces) shown in the image.
(Round corners at the bottom)