ArduinoÆüËܸì¥ê¥Õ¥¡¥ì¥ó¥¹


Arduino¸À¸ì

Arduino¸À¸ì¤ÏC/C++¤ò¥Ù¡¼¥¹¤Ë¤·¤Æ¤ª¤ê¡¢C¸À¸ì¤Î¤¹¤Ù¤Æ¤Î¹½Â¤¤È¡¢¤¤¤¯¤Ä¤«¤ÎC++¤Îµ¡Ç½¤ò¥µ¥Ý¡¼¥È¤·¤Æ¤¤¤Þ¤¹¡£¤Þ¤¿¡¢AVR Libc¤Ë¥ê¥ó¥¯¤µ¤ì¤Æ¤¤¤Æ¡¢¤½¤Î´Ø¿ô¤òÍøÍѤǤ­¤Þ¤¹¡£

setup()
loop()

À©¸æʸ

if
if else
switch case
for
while
do while
break
continue
return
goto

´ðËÜŪ¤Êʸˡ

; (¥»¥ß¥³¥í¥ó)
{} (ÇÈ¥«¥Ã¥³)
¥³¥á¥ó¥È
#define
#include

»»½Ñ±é»»»Ò

+ - * /
% (¾ê;)
= (ÂåÆþ)

Èæ³Ó±é»»»Ò

== != < > <= >=

¥Ö¡¼¥ë±é»»»Ò

&& (ÏÀÍýÀÑ)
|| (ÏÀÍýÏÂ)
! (ÈÝÄê)

¥Ó¥Ã¥È±é»»»Ò

¥Ó¥Ã¥È±é»»»Ò¤ÏÊÑ¿ô¤ò¥Ó¥Ã¥È¤Î¥ì¥Ù¥ë¤Ç·×»»¤¹¤ë¤¿¤á¤Î¤â¤Î¤Ç¤¹¡£¥Ó¥Ã¥È±é»»»Ò¤Ë¤è¤Ã¤Æ¡¢¹­ÈÏ°Ï¤Ê¥×¥í¥°¥é¥ß¥ó¥°¾å¤ÎÌäÂê¤ò²ò·è¤¹¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£

& (AND)
| (OR)
^ (XOR)
~ (NOT)
<< (º¸¥·¥Õ¥È) >> (±¦¥·¥Õ¥È)
¥Ý¡¼¥ÈÁàºî

Ê£¹ç±é»»»Ò

++ (²Ã»») -- (¸º»»)
+= -= *= /=
&= (AND)
|= (OR)

¥Ç¡¼¥¿·¿

bool (boolean)
char
unsigned char
byte
int (À°¿ô·¿)
unsigned int (Éä¹æ¤Ê¤·À°¿ô·¿)
word
long (longÀ°¿ô·¿)
unsigned long (Éä¹æ¤Ê¤·longÀ°¿ô·¿)
float (ÉâÆ°¾®¿ôÅÀ·¿)
double (ÇÜÀºÅÙÉâÆ°¾®¿ôÅÀ·¿)
ʸ»úÎó(ÇÛÎó)
ÇÛÎó
void

String¥¯¥é¥¹

String¥¯¥é¥¹¤Ïʸ»ú¤ò°·¤¦ÇÛÎ󷿤Îʸ»úÎó¤è¤ê¤âÊ£»¨¤ÊÏ¢·ë¡¢Äɲá¢ÃÖ´¹¡¢¸¡º÷¤È¤¤¤Ã¤¿Áàºî¤¬²Äǽ¤Ç¤¹¡£¤½¤Î¤«¤ï¤ê¡¢ÇÛÎ󷿤è¤ê¿¤¯¤Î¥á¥â¥ê¤ò¾ÃÈñ¤·¤Þ¤¹¡£¥À¥Ö¥ë¥¯¥©¡¼¥Æ¡¼¥·¥ç¥ó¤Ç°Ï¤Þ¤ì¤¿Ê¸»úÎóÄê¿ô¤ÏÇÛÎó¤È¤·¤Æ½èÍý¤µ¤ì¤Þ¤¹¡£


String()
´Ø¿ô
±é»»»Ò

Äê¿ô

Äê¿ô¤Ï¥×¥í¥°¥é¥à¤Î¤Ê¤«¤ÇÃͤ¬ÊѲ½¤·¤Ê¤¤ÊÑ¿ô¤È¹Í¤¨¤ë¤È¤¤¤¤¤Ç¤·¤ç¤¦¡£Arduino¸À¸ì¤Ç¤¢¤é¤«¤¸¤áÄêµÁ¤µ¤ì¤Æ¤¤¤ëÄê¿ô¤È¡¢¥æ¡¼¥¶¡¼¤¬¼«Ê¬¤ÇÄêµÁ¤·¤Æ»È¤¦Äê¿ô¤¬¤¢¤ê¤Þ¤¹¡£¤ª¤â¤Ë¥×¥í¥°¥é¥à¤Î¥á¥ó¥Æ¥Ê¥ó¥¹À­¤ò¹â¤á¤ë¤¿¤á¤Ë»È¤ï¤ì¤Þ¤¹¡£

true/false (ÏÀÍý¥ì¥Ù¥ë¤òÄêµÁ¤¹¤ëÄê¿ô)
HIGH/LOW (¥Ô¥ó¤Î¥ì¥Ù¥ë¤òÄêµÁ¤¹¤ëÄê¿ô)
INPUT/OUTPUT (¥Ç¥¸¥¿¥ë¥Ô¥ó¤òÄêµÁ¤¹¤ëÄê¿ô)
À°¿ô¤ÎÄê¿ô
ÉâÆ°¾®¿ôÅÀ¿ô¤ÎÄê¿ô

ÊÑ¿ô¤Î±þÍÑ

ÊÑ¿ô¤Î¥¹¥³¡¼¥×
Static
volatile
const
PROGMEM¤ÈF¥Þ¥¯¥í
Cast
sizeof

¥Ç¥¸¥¿¥ëÆþ½ÐÎÏ´Ø¿ô

pinMode(pin, mode)
digitalWrite(pin, value)
digitalRead(pin)

¥¢¥Ê¥í¥°Æþ½ÐÎÏ´Ø¿ô

analogRead(pin)
analogWrite(pin, value)
analogReference(type)
analogReadResolution(bits)
analogWriteResolution(bits)

¤½¤Î¾¤ÎÆþ½ÐÎÏ´Ø¿ô

shiftOut(dataPin, clockPin, bitOrder, value)
shiftIn(dataPin, clockPin, bitOrder)
pulseIn(pin, value, timeout)
tone(pin, frequency)
noTone(pin)

»þ´Ö¤Ë´Ø¤¹¤ë´Ø¿ô

millis()
micros()
delay(ms)
delayMicroseconds(us)

¿ô³ØŪ¤Ê´Ø¿ô

min()¡¢max()¡¢abs()¡¢constraint()¤Î³Æ´Ø¿ô¤Ï¼ÂÁõ¤ÎÅÔ¹ç¤Ë¤è¤ê¡¢¥«¥Ã¥³Æâ¤Ç´Ø¿ô¤ò»È¤Ã¤¿¤êÊÑ¿ô¤òÁàºî¤¹¤ë¤³¤È¤¬¤Ç¤­¤Þ¤»¤ó¡£¤¿¤È¤¨¤Ð¡¢min(a++, 100)¤È¤¹¤ë¤ÈÀµ¤·¤¤Åú¤¬ÆÀ¤é¤ì¤Þ¤»¤ó¡£¤«¤ï¤ê¤Ë¡¢¼¡¤Î¤è¤¦¤Ë¤·¤Æ¤¯¤À¤µ¤¤¡£
¡¡a++;
¡¡min(a, 100);

min(x, y)
max(x, y)
abs(x)
constrain(x, a, b)
map(value, fromLow, fromHigh, toLow, toHigh)
pow(base, exponent)
sqrt(x)

»°³Ñ´Ø¿ô

sin(rad)
cos(rad)
tan(rad)

Íð¿ô¤Ë´Ø¤¹¤ë´Ø¿ô

randomSeed(seed)
random(min, max)

¥Ó¥Ã¥È¤È¥Ð¥¤¥È¤ÎÁàºî

lowByte()
highByte()
bitRead()
bitWrite()
bitSet()
bitClear()
bit()

³°Éô³ä¤ê¹þ¤ß

attachInterrupt(interrupt, function, mode)
detachInterrupt(interrupt)

³ä¤ê¹þ¤ß

interrupts()
noInterrupts()

¥·¥ê¥¢¥ëÄÌ¿®

¾¤Î¥³¥ó¥Ô¥å¡¼¥¿¤ä¥Ç¥Ð¥¤¥¹¤ÈÄÌ¿®¤¹¤ë¤¿¤á¤Ë¡¢¤É¤Î¥Ü¡¼¥É¤Ë¤âºÇÄã1¤Ä¤Î¥·¥ê¥¢¥ë¥Ý¡¼¥È¤¬ÍÑ°Õ¤µ¤ì¤Æ¤¤¤Þ¤¹¡£Arduino Uno¤Ç¤Ï¥Ô¥ó0¤È1¤¬¥·¥ê¥¢¥ë¥Ý¡¼¥È¤Î¥Ô¥ó¤Ç¡¢¤³¤Î2¥Ô¥ó¤òÄÌ¿®¤Ë»ÈÍѤ·¤Æ¤¤¤ë´Ö¤Ï¡¢¥Ç¥¸¥¿¥ëÆþ½ÐÎϤȤ·¤Æ»È¤¦¤³¤È¤Ï¤Ç¤­¤Þ¤»¤ó¡£
Arduino IDE¤Ï¥·¥ê¥¢¥ë¥â¥Ë¥¿¤òÈ÷¤¨¤Æ¤¤¤Æ¡¢Arduino¥Ü¡¼¥É¤¬Á÷¿®¤·¤¿¥á¥Ã¥»¡¼¥¸¤òɽ¼¨¤·¤¿¤ê¡¢µÕ¤ËIDE¤«¤é¥Ü¡¼¥É¤Ø¥á¥Ã¥»¡¼¥¸¤òÁ÷¿®¤¹¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£

Serial.begin(speed)
Serial.end()
Serial.available()
Serial.read()
Serial.peek()
Serial.flush()
Serial.print(data, format)
Serial.println(data, format)
Serial.write(val)
Serial.readString()

ɸ½à¥é¥¤¥Ö¥é¥ê

Arduino¤Î¥é¥¤¥Ö¥é¥ê¤Ï¡¢¤¢¤é¤«¤¸¤áIDE¤ËÉÕ°¤¹¤ëɸ½à¤Î¥é¥¤¥Ö¥é¥ê¤È¡¢¥³¥ß¥å¥Ë¥Æ¥£¡¼¤Î¥á¥ó¥Ð¡¼¤«¤é´ó¹Æ¤µ¤ì¤¿¥é¥¤¥Ö¥é¥ê¤Î2¼ïÎब¤¢¤ê¤Þ¤¹¡£´ó¹Æ¤µ¤ì¤¿¤â¤Î¤Ï¥æ¡¼¥¶¡¼¤¬¸Ä¡¹¤Ë¥À¥¦¥ó¥í¡¼¥É¤·¤Æ¥¤¥ó¥¹¥È¡¼¥ë¤¹¤ëɬÍפ¬¤¢¤ê¤Þ¤¹¡£

¥é¥¤¥Ö¥é¥ê¤Î»È¤¤Êý

EEPROM

Arduino¥Ü¡¼¥É¤¬ÅëºÜ¤¹¤ë¥Þ¥¤¥¯¥í¥³¥ó¥È¥í¡¼¥é¤ÏEEPROM¤È¸Æ¤Ð¤ì¤ë¥á¥â¥ê¤ò»ý¤Ã¤Æ¤¤¤Þ¤¹¡£EEPROM¤Ï(¤Þ¤ë¤Ç¾®¤µ¤Ê¥Ï¡¼¥É¥Ç¥£¥¹¥¯¤Î¤è¤¦¤Ë)ÅŸ»¤òÀڤäƤâÆâÍƤ¬¾Ã¤¨¤Þ¤»¤ó¡£¤½¤ÎÍÆÎ̤ϵ¡¼ï¤Ë¤è¤Ã¤Æ°Û¤Ê¤ê¡¢Arduino Uno¤ÎATmega328P¤Ï1024¥Ð¥¤¥È¡¢Nano Every¤Ï256¥Ð¥¤¥È¤Ç¤¹¡£
MKR¥Õ¥¡¥ß¥ê¡¼¤Ê¤É¤ÎSAMD¥Á¥Ã¥×¤ÏEEPROM¤òÆ⢤·¤Æ¤¤¤Ê¤¤¤¿¤á¡¢ÉÔ´øȯÀ­¤Îµ­²±¥¨¥ê¥¢¤ò»È¤¤¤¿¤¤¾ì¹ç¤ÏÊ̤ÎÊýË¡¤¬É¬ÍפǤ¹¡£
¤³¤Î¥é¥¤¥Ö¥é¥ê¤ÏEEPROM¤ËÂФ¹¤ë½ñ¤­¹þ¤ß¤ÈÆɤ߹þ¤ß¤ò²Äǽ¤Ë¤·¤Þ¤¹¡£

EEPROM.read(address)
EEPROM.write(address, value)

SoftwareSerial

¥½¥Õ¥È¥¦¥§¥¢¥·¥ê¥¢¥ë¥é¥¤¥Ö¥é¥ê¤ÏArduino¥Ü¡¼¥É¤Î0¡Á1Èְʳ°¤Î¥Ô¥ó¤ò»È¤Ã¤Æ¥·¥ê¥¢¥ëÄÌ¿®¤ò¹Ô¤¦¤¿¤á¤Ë³«È¯¤µ¤ì¤Þ¤·¤¿¡£ËÜÍè¥Ï¡¼¥É¥¦¥§¥¢¤Ç¼Â¸½¤µ¤ì¤Æ¤¤¤ëµ¡Ç½¤ò¥½¥Õ¥È¥¦¥§¥¢¤Ë¤è¤Ã¤ÆÊ£À½¤·¤¿¤Î¤Ç¡¢SoftwareSerial¤È̾ÉÕ¤±¤é¤ì¤Þ¤·¤¿¡£

¥½¥Õ¥È¥¦¥§¥¢¥·¥ê¥¢¥ë¤Î¥µ¥ó¥×¥ë¥³¡¼¥É
SoftwareSerial(rxPin, txPin)
SoftwareSerial: begin(speed)
SoftwareSerial: available()
SoftwareSerial: isListening()
SoftwareSerial: overflow()
SoftwareSerial: read()
SoftwareSerial: print(data)
SoftwareSerial: println(data)
SoftwareSerial: listen()
SoftwareSerial: write(data)

Stepper

¥æ¥Ë¥Ý¡¼¥é¤ª¤è¤Ó¥Ð¥¤¥Ý¡¼¥é¤Î¥¹¥Æ¥Ã¥Ñ¥â¡¼¥¿¤ò¥³¥ó¥È¥í¡¼¥ë¤¹¤ë¤¿¤á¤Î¥é¥¤¥Ö¥é¥ê¤Ç¤¹¡£¤³¤Î¥é¥¤¥Ö¥é¥ê¤òÍøÍѤ¹¤ë¤Ë¤Ï¡¢¥¹¥Æ¥Ã¥Ñ¥â¡¼¥¿¤ÈÀ©¸æ¤Î¤¿¤á¤ÎŬÀڤʥϡ¼¥É¥¦¥§¥¢¤¬É¬ÍפǤ¹¡£

Stepper¥é¥¤¥Ö¥é¥ê¤Î¥µ¥ó¥×¥ë¥³¡¼¥É
Stepper(steps, pin1, pin2, pin3, pin4)
Stepper: setSpeed(rpms)
Stepper: step(steps)

Wire

2Àþ¥¤¥ó¥¿¥Õ¥§¥¤¥¹(TWI/I2C)¤Î¥Ç¥Ð¥¤¥¹¤È¤ÎÄÌ¿®¤ò¥µ¥Ý¡¼¥È¤¹¤ë¥é¥¤¥Ö¥é¥ê¤Ç¤¹¡£

³µÍ×
Wire.begin(address)
Wire.requestFrom(address, count)
Wire.beginTransmission(address)
Wire.endTransmission()
Wire.write(value)
Wire.available()
Wire.read()
Wire.onReceive(handler)
Wire.onRequest(handler)

SPI

Serial Peripheral Interface (SPI)¥Ð¥¹¤ËÀܳ¤µ¤ì¤¿¥Ç¥Ð¥¤¥¹¤È¤ÎÄÌ¿®¤Ë»ÈÍѤ·¤Þ¤¹¡£

³µÍ×
SPI.begin()
SPI.end()
SPI.setBitOrder(order)
SPI.setClockDivider(divider)
SPI.setDataMode(mode)
SPI.transfer(value)

Servo

¥µ¡¼¥Ü¥â¡¼¥¿¤ò¥³¥ó¥È¥í¡¼¥ë¤·¤Þ¤¹¡£

³µÍ×
attach(pin)
write(angle)
writeMicroseconds(uS)
read()
attached()
detach()

Firmata

¥Û¥¹¥È¥³¥ó¥Ô¥å¡¼¥¿¾å¤Î¥½¥Õ¥È¥¦¥§¥¢¤È¤ÎÄÌ¿®¤ËÍѤ¤¤ë¥·¥ê¥¢¥ë¥×¥í¥È¥³¥ë¤Ç¤¹¡£

¥á¥½¥Ã¥É
¥³¡¼¥ë¥Ð¥Ã¥¯´Ø¿ô
¥µ¥ó¥×¥ë¥³¡¼¥É

LiquidCrystal

¤³¤Î¥é¥¤¥Ö¥é¥ê¤ò»È¤¦¤³¤È¤Ç¡¢Hitachi HD44780¤È¤½¤Î¸ß´¹¥Á¥Ã¥×¥»¥Ã¥È¤ò¥Ù¡¼¥¹¤Ë¤·¤¿LCD¤òÀ©¸æ¤Ç¤­¤Þ¤¹¡£4¥Ó¥Ã¥È¤È8¥Ó¥Ã¥ÈξÊý¤Î¥â¡¼¥É¤ò¥µ¥Ý¡¼¥È¤·¤Æ¤¤¤Þ¤¹¡£

LiquidCrystal()
begin(cols, rows)
clear()
home()
setCursor(col, row)
write(data)
print(data)
cursor()
noCursor()
blink()
noBlink()
display()
noDisplay()
scrollDisplayLeft()
scrollDisplayRight()
autoscroll()
noAutoscroll()
leftToRight()
rightToLeft()
createChar(num, data)

Ethernet¥é¥¤¥Ö¥é¥ê

Arduino Ethernet Shield¤ò»È¤Ã¤ÆArduino¥Ü¡¼¥É¤ò¥¤¥ó¥¿¡¼¥Í¥Ã¥È¤ËÀܳ¤¹¤ë¤È¤­¤Ë»È¤¦¥é¥¤¥Ö¥é¥ê¤Ç¤¹¡£¥µ¡¼¥Ð(³°Éô¤«¤é¤ÎÀܳ)¡¢¥¯¥é¥¤¥¢¥ó¥È(³°¤Ø¸þ¤«¤¦Àܳ)¤ÎξÊý¤ËÂбþ¤Ç¤­¤Þ¤¹¡£

Ethernet¥¯¥é¥¹
begin(mac, ip)
localIP()
maintain()

Server¥¯¥é¥¹
EthernetServer(port)
begin()
available()
write(data)
print(data)
println(data)

Client¥¯¥é¥¹
EthernetClient()
connected()
connect(server, port)
write(data)
print(data)
println(data)
available()
read()
flush()
stop()

SD Library

SD¥«¡¼¥É¤ÎÆɤ߽ñ¤­¤ò²Äǽ¤Ë¤·¤Þ¤¹¡£

³µÍ×

SD class
SD.begin()
SD.exists()
SD.mkdir()
SD.open()
SD.remove()
SD.rmdir()

File class
available()
close()
flush()
peek()
position()
print()
println()
seek()
size()
read()
write()
isDirectory()
openNextFile()
rewindDirectory()

´ó¹Æ¤µ¤ì¤¿¥é¥¤¥Ö¥é¥ê

Arduino¥³¥ß¥å¥Ë¥Æ¥£¤Î¥á¥ó¥Ð¡¼¤«¤é´ó¹Æ¤µ¤ì¤¿¥é¥¤¥Ö¥é¥ê¤¬¿ô¿¤¯Â¸ºß¤·¡¢¥æ¡¼¥¶¡¼¤Ï¼«Ê¬¤Î¥¹¥±¥Ã¥Á¤Ç¤½¤ì¤é¤òÍøÍѤǤ­¤Þ¤¹¡£¤³¤³¤Ç¤Ï¤½¤Î¤¦¤Á¤Î¤´¤¯°ìÉô¤ò¾Ò²ð¤·¤Þ¤¹¡£

MsTimer2(¥ß¥êÉÃñ°Ì¤Ç»ØÄꤹ¤ë¥¿¥¤¥Þ)
ServoTimer1(¥µ¡¼¥Ü¥â¡¼¥¿¤Î¥É¥é¥¤¥Ö)
CapSense (ÀÅÅÅÍÆÎÌ¥»¥ó¥µ)
TLC5940 (16ch/12bit PWM¥³¥ó¥È¥í¡¼¥é)
¸Å¤¤Ê¸»úÎó½èÍý¥é¥¤¥Ö¥é¥ê

Creative Commons Attribution-ShareAlike 3.0 License.
¤³¤Î¥É¥­¥å¥á¥ó¥È¤ÏArduino Team¤Ë¤è¤ê¼¹É®¤µ¤ì¡¢Takumi Funada¤¬ËÝÌõ¤·¡¢°ìÉô²ÃÉ®½¤Àµ¤·¤¿¤â¤Î¤Ç¤¹
¤´°Õ¸«¤Ïtf at musashinodenpa.com¤Þ¤Ç¤ªÁ÷¤ê¤¯¤À¤µ¤¤ [¥É¥­¥å¥á¥ó¥È°ìÍ÷]