Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Workshops On Designing Electronic Toys #1

Hirotaka Nakajima
May 27, 2014
150

Workshops On Designing Electronic Toys #1

Hirotaka Nakajima

May 27, 2014
Tweet

More Decks by Hirotaka Nakajima

Transcript

  1. 5IFTFTMJEFTBSFDPQZSJHIU˜)JSPUBLB/BLBKJNB3FEJTUSJCVUFBOEEJTDMPTVSFPGUIFTFTMJEFTBSFOPUQFSNJUUFEXJUIPVUQFSNJTTJPOT ,FJP6OJWFSTJUZJTMJDFOTFECZJUTDPQZSJHIUIPMEFST Arduino 4 • Integrated Single-board micro controller •

    AVR micro controller and IDE(Integrated Development Environment) • Aim to communicate with sensors or PCs • Easy to use as a prototyping ! • Open source hardware • We’re using Arduino compatible architecture • more freedom, less money :)
  2. 5IFTFTMJEFTBSFDPQZSJHIU˜)JSPUBLB/BLBKJNB3FEJTUSJCVUFBOEEJTDMPTVSFPGUIFTFTMJEFTBSFOPUQFSNJUUFEXJUIPVUQFSNJTTJPOT ,FJP6OJWFSTJUZJTMJDFOTFECZJUTDPQZSJHIUIPMEFST Arduino Programming 5 • Processing-based Language (C like

    syntax) • 2 Main functions • setup() • Called once on the boot • loop() • Continuous loop ! ! • http://arduino.cc/en/Reference/HomePage int ledPin=8; ! void setup() { pinMode(ledPin,OUTPUT); } ! void loop() { digitalWrite(ledPin,1); delay(500); digitalWrite(ledPin,0); delay(500); }
  3. 5IFTFTMJEFTBSFDPQZSJHIU˜)JSPUBLB/BLBKJNB3FEJTUSJCVUFBOEEJTDMPTVSFPGUIFTFTMJEFTBSFOPUQFSNJUUFEXJUIPVUQFSNJTTJPOT ,FJP6OJWFSTJUZJTMJDFOTFECZJUTDPQZSJHIUIPMEFST Digital Output 7 • Control On/Off • digitalWrite([PIN#],

    [Value]) • e.g.)
 setup(){
 int ledPin = 8; //LED is connected to digital output pin #8
 }
 
 loop(){
 digitalWrite(ledPin, HIGH); //set the LED on
 delay(1000); // wait for a second
 digitalWrite(ledPin, LOW); //set the LED off
 delay(1000); // wait for a second
 }
  4. 5IFTFTMJEFTBSFDPQZSJHIU˜)JSPUBLB/BLBKJNB3FEJTUSJCVUFBOEEJTDMPTVSFPGUIFTFTMJEFTBSFOPUQFSNJUUFEXJUIPVUQFSNJTTJPOT ,FJP6OJWFSTJUZJTMJDFOTFECZJUTDPQZSJHIUIPMEFST Where should I put the LED? 9 •

    Generally Data sheet may help
 http://www.atmel.com/Images/doc8161.pdf 8P C1 (ADC1/PCINT9) C0 (ADC0/PCINT8) DC7 ND REF DC6 CC B5 (SCK/PCINT5) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 28 27 26 25 24 23 22 21 20 19 18 17 16 15 (PCINT14/RESET) PC6 (PCINT16/RXD) PD0 (PCINT17/TXD) PD1 (PCINT18/INT0) PD2 (PCINT19/OC2B/INT1) PD3 (PCINT20/XCK/T0) PD4 VCC GND (PCINT6/XTAL1/TOSC1) PB6 (PCINT7/XTAL2/TOSC2) PB7 (PCINT21/OC0B/T1) PD5 (PCINT22/OC0A/AIN0) PD6 (PCINT23/AIN1) PD7 (PCINT0/CLKO/ICP1) PB0 PC5 (ADC5/SCL/PCINT13) PC4 (ADC4/SDA/PCINT12) PC3 (ADC3/PCINT11) PC2 (ADC2/PCINT10) PC1 (ADC1/PCINT9) PC0 (ADC0/PCINT8) GND AREF AVCC PB5 (SCK/PCINT5) PB4 (MISO/PCINT4) PB3 (MOSI/OC2A/PCINT3) PB2 (SS/OC1B/PCINT2) PB1 (OC1A/PCINT1) PDIP
  5. 5IFTFTMJEFTBSFDPQZSJHIU˜)JSPUBLB/BLBKJNB3FEJTUSJCVUFBOEEJTDMPTVSFPGUIFTFTMJEFTBSFOPUQFSNJUUFEXJUIPVUQFSNJTTJPOT ,FJP6OJWFSTJUZJTMJDFOTFECZJUTDPQZSJHIUIPMEFST Digital Input 14 int ledPin = 13; //

    LED connected to digital pin 13 int inPin = 7; // pushbutton connected to digital pin 7 int val = 0; // variable to store the read value ! void setup() { pinMode(ledPin, OUTPUT); // sets the digital pin 13 as output pinMode(inPin, INPUT); // sets the digital pin 7 as input } ! void loop() { val = digitalRead(inPin); // read the input pin digitalWrite(ledPin, val); // sets the LED to the button's value }
  6. 5IFTFTMJEFTBSFDPQZSJHIU˜)JSPUBLB/BLBKJNB3FEJTUSJCVUFBOEEJTDMPTVSFPGUIFTFTMJEFTBSFOPUQFSNJUUFEXJUIPVUQFSNJTTJPOT ,FJP6OJWFSTJUZJTMJDFOTFECZJUTDPQZSJHIUIPMEFST Use LED as a sensor 20 • According

    to Wikipedia: • LED as light sensor:
 "A LED is simply a diode that has been doped specifically for efficient light emission and has been packaged in a transparent case. Therefore, if inserted into a circuit in the same way as a photodiode, which is essentially the same thing, the LED will perform the same function.” • Photodiode:
 "A photodiode is a type of photodetector capable of converting light into either current or voltage, depending upon the mode of operation."
  7. 5IFTFTMJEFTBSFDPQZSJHIU˜)JSPUBLB/BLBKJNB3FEJTUSJCVUFBOEEJTDMPTVSFPGUIFTFTMJEFTBSFOPUQFSNJUUFEXJUIPVUQFSNJTTJPOT ,FJP6OJWFSTJUZJTMJDFOTFECZJUTDPQZSJHIUIPMEFST LED2 22 int ledPin=8; int sensorPin = A0;

    int sensorValue = 0; ! void setup(){ pinMode(ledPin, OUTPUT); } ! void loop(){ sensorValue = analogRead(sensorPin); if(sensorValue>250){ digitalWrite(ledPin, 0); } else { digitalWrite(ledPin,1); } }