アフィリエイト広告を利用しています
アクセスカウンター
ファン
<< 2018年08月 >>
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31  
最新記事
写真ギャラリー
カテゴリーアーカイブ
タグクラウド
月別アーカイブ
日別アーカイブ
最新コメント

広告

この広告は30日以上更新がないブログに表示されております。
新規記事の投稿を行うことで、非表示にすることが可能です。
posted by fanblog

2018年08月13日

【番外編10】Groovesizer mk1 / ブレッドボード

Groovesizer mk1: DIY 16-step sequencer and synth

前回の"ARDUINO STEP SEQUENCER" を見つけたときに一緒にGroovesizer mk1: DIY 16-step sequencer and synthというのも見つけた

Groovesizer mk1.png

"DIY 16-step sequencer and synth"とのことで16ステップシーケンサーらしいんだが・・・ノブ5つはいいとしてボタンも5つで8LEDで16ステップシーケンサーってどんなん?

このサイトに置いてあるYouTube動画で操作方法を説明してるんだがいまいちよくわからない

というわけで作ってみる
Groovesizer mk1 Manual

このサイトを読むとこれがAuduinoを元にしているらしいことが書いてあって、そしてMANUALが置いてありました

Groovesizer mk1 Manual.png

MANUALを読むといろいろできることがわかります

素晴らしい!
Groovesizer mk1 / ブレッドボード

ブレッドボードで確認します

(1)配線

今回MIDI outは配線しません

(パーツ)
   1. 2.2kΩ 抵抗 x1
   2. 220Ω 抵抗 x9
   3. 100nF コンデンサー (104) x1
   4. 100uF コンデンサー x1
   5. 5kΩ トリマポテンショメーター x5
   6. タクトスイッチ x5
   7. 5mm LED x8
   8. 8Ω 0.5Wスピーカー x1
   9. Arduino UNO x1

IMG_0052.jpg

Groovsizer mk1.png

(2)スケッチ

このスケッチは結構長めなのでzipファイルのダウンロードリンク先を置いておきます

(3)実行

実行してみましたが・・・



この動画の流れは

  1. 上記の配線方式では音がほとんど聞こえない
  2. コンデンサーを飛ばしてスピーカーに繋ぐと幾らかは聞こえるけど満足いく音量じゃ無い
  3. ならばとボリューム付きアンプにつないだら挙動がおかしい
  4. じゃ、Groovesizer mk1のサイトと同じくステレオピンジャック経由でスピーカーに繋ぐと・・・よく聞こえるようになる

という感じでした

まあ、はじめから書かれている通りに作りなさいということなんですが・・・

これをミント缶に入れたいんだけど・・・入るかな?

目的がだんだん「とりあえずミントサイズ缶に入れてみる」になってきたな・・・

ではまた〜


【永久保証付き】Arduino Uno

新品価格
¥3,240から


Raspberry Pi3 Model B ボード&ケースセット (Element14版, Clear)-Physical Computing Lab

新品価格
¥5,780から


Arduinoをはじめよう 第3版 (Make:PROJECTS)

新品価格
¥2,160から


Arduinoをはじめよう 互換キット UNO R3対応互換ボード 初心者専用実験キット 基本部品セット20 in 1 Arduino sidekick basic kit

新品価格
¥3,780から


Arduinoをはじめようキット

新品価格
¥4,310から


Arduino エントリーキット(Uno版)- Physical Computing Lab

新品価格
¥4,320から


タミヤ 楽しい工作シリーズ No.216 3ch RCロボット製作セット 70216

新品価格
¥6,327から


エレキット 水圧式ロボットアーム MR-9105

新品価格
¥4,560から


エレキット バトルタイタン2 MR-9101R

新品価格
¥3,163から


世界最小★OZO-010102-0102 World's Smallest SMART Robot - Dual Pack, 1 Crystal White & 1 Titanium Black 2 Bonus Limited-Edition Skins スマートロボット Ozobot社【並行輸入】

新品価格
¥6,000から


タミヤ 楽しい工作シリーズ No.211 アームクローラー工作セット 70211

新品価格
¥1,345から


タミヤ 楽しい工作シリーズ No.97 ツインモーターギヤーボックス (70097)

新品価格
¥587から


タミヤ 楽しい工作シリーズ No.106 4チャンネル・リモコンボックス (70106)

新品価格
¥1,118から


posted by riserobo: at 18:12| Comment(0) | TrackBack(0) | Auduino

2018年08月06日

【番外編9】ARDUINO STEP SEQUENCER / ミント缶

ARDUINO STEP SEQUENCER

前回このサイト(https://www.instructables.com/id/Arduino-Step-Sequencer/)を参考に"ARDUINO STEP SEQUENCER"をブレッドボードにてテストしました

今回はミント缶に組みます
ARDUINO STEP SEQUENCER / ミント缶

ミント缶で組みやすいように少しパーツを変えて、Arduino UNOからArduino NANOに変更します

(パーツ)
  1. タクトスイッチ X8
  2. トグルスイッチ X1
  3. 3mm LED X1
  4. 10KΩ 抵抗 X9
  5. 10K ポテンショメーター X4
  6. 8Ω 2W スピーカー X1

(1)配線

ポテンショメーターのノブとタクトスイッチのボタンがミント缶の蓋から出るように(1)ポテンショメーターと(2)タクトスイッチを載せる基板を別にして2枚構成にしました

上面
IMG_0068.jpg

下面
IMG_0069.jpg

2枚構成
IMG_0070.jpg

作った後で、ボタンの長〜いタクトスイッチを使うっていう手もあったなと気が付いた

(2)スケッチ

スケッチは前回と一緒

(3)組み立て

動作テストをしてからミント缶に入れて、さらに動作テストをしています



上面図
IMG_0066.jpg

斜め図
IMG_0067.jpg

これでひとまず完成です

ではまた〜


【永久保証付き】Arduino Uno

新品価格
¥3,240から


Raspberry Pi3 Model B ボード&ケースセット (Element14版, Clear)-Physical Computing Lab

新品価格
¥5,780から


Arduinoをはじめよう 第3版 (Make:PROJECTS)

新品価格
¥2,160から


Arduinoをはじめよう 互換キット UNO R3対応互換ボード 初心者専用実験キット 基本部品セット20 in 1 Arduino sidekick basic kit

新品価格
¥3,780から


Arduinoをはじめようキット

新品価格
¥4,310から


Arduino エントリーキット(Uno版)- Physical Computing Lab

新品価格
¥4,320から


タミヤ 楽しい工作シリーズ No.216 3ch RCロボット製作セット 70216

新品価格
¥6,327から


エレキット 水圧式ロボットアーム MR-9105

新品価格
¥4,560から


エレキット バトルタイタン2 MR-9101R

新品価格
¥3,163から


世界最小★OZO-010102-0102 World's Smallest SMART Robot - Dual Pack, 1 Crystal White & 1 Titanium Black 2 Bonus Limited-Edition Skins スマートロボット Ozobot社【並行輸入】

新品価格
¥6,000から


タミヤ 楽しい工作シリーズ No.211 アームクローラー工作セット 70211

新品価格
¥1,345から


タミヤ 楽しい工作シリーズ No.97 ツインモーターギヤーボックス (70097)

新品価格
¥587から


タミヤ 楽しい工作シリーズ No.106 4チャンネル・リモコンボックス (70106)

新品価格
¥1,118から


posted by riserobo: at 20:56| Comment(0) | TrackBack(0) | Auduino

2018年07月31日

【番外編8】ARDUINO STEP SEQUENCER / ブレッドボード

ARDUINO STEP SEQUENCER

次はArduinoでステップシーケンサーを作りたいと思ってググってたら、その名も"ARDUINO STEP SEQUENCER" のサイトを見つけた

"A simple programmable 8 step tone sequencer"とのことで、tone機能を使った8ステップシーケンサーらしい

まずはこのサイト(http://www.instructables.com/id/Arduino-Step-Sequencer/) を参考にブレッドボードで組んでみます
ARDUINO STEP SEQUENCER / ブレッドボード

ブレッドボードで組みやすいように少しパーツを変えて

(パーツ)
  1. タクトスイッチ X8
  2. スライドスイッチ X1
  3. LED X1
  4. 10KΩ 抵抗 X9
  5. 100K トリマポテンショメーター X4
  6. 8Ω 0.5W スピーカー X1

(1)配線

配線はこんな感じ

ARDUINO.STEP SEQUENCER.jpg

Arduino Step Sequencer.png

(2)スケッチ

スケッチは"ARDUINO STEP SEQUENCER"のサイト からそのままコピーして使うとエラーが出るので次の2箇所を書き換えて使う

 (修正前)
   Serial.print (254, BYTE);
   Serial.print (192, BYTE);

 (修正後)
   Serial.print (254);
   Serial.print (192);

で、修正したのがこれ↓

Arduino Step Sequencer
――――――――――(Arduino Step Sequencer)――――――――――
/* ======================================================================
Arduino Punk Console
A simple programmable 8 step tone sequencer
by dano/beavisaudio.com
Revs
-----------------------------------
15 Sept djh initial version
======================================================================*/
// Map all the input and output pins
#define AnalogInFrequency 1
#define AnalogInTempo 2
#define AnalogInDuration 0
#define DigitalOutSignal 11
#define DigitalInSwitch0 2
#define DigitalInSwitch1 3
#define DigitalInSwitch2 4
#define DigitalInSwitch3 5
#define DigitalInSwitch4 6
#define DigitalInSwitch5 7
#define DigitalInSwitch6 8
#define DigitalInSwitch7 9
#define DigitalInStartStop 10
#define DigitalOutLED 12
// Set up the array for each step
int steps[] = {100,120,140,160,180,200,220,240};
// misc housekeeping
int duration = 50;
int pitchval = 1;
int fPlayMode = true;
int lastPushedStep = -1;
// Initialize the tempo
int tempo = 100;
void setup()
{
// setup pin modes (Digital pins are input by default, but
// I like to set 'em explicitly just so the code is clear.
pinMode (DigitalInSwitch0, INPUT);
pinMode (DigitalInSwitch1, INPUT);
pinMode (DigitalInSwitch2, INPUT);
pinMode (DigitalInSwitch3, INPUT);
pinMode (DigitalInSwitch4, INPUT);
pinMode (DigitalInSwitch5, INPUT);
pinMode (DigitalInSwitch6, INPUT);
pinMode (DigitalInSwitch7, INPUT);
pinMode (DigitalInStartStop, INPUT);
pinMode (DigitalOutSignal, OUTPUT);
pinMode (DigitalOutLED, OUTPUT);

}


void loop()
{
// Main sequence loop
for (int i=0; i<8; i++)
{
// Are we playing or stopping?
fPlayMode = digitalRead (DigitalInStartStop);
digitalWrite (DigitalOutLED, HIGH);
// Check the Hardware
readSwitches();
readPots();

// update the display
updateDisplay();

// Make the noise
if (fPlayMode)
{
freqout (steps[i], duration);
}
digitalWrite (DigitalOutLED, LOW);

// Pause between steps
delay (tempo);
}
}

void updateDisplay()
{
Serial.print (254);
Serial.print (192);
Serial.print ("T:");
Serial.print (tempo);
Serial.print (" d:");
Serial.print (duration);
if (lastPushedStep != -1)
{
Serial.print ("*");
Serial.print (lastPushedStep);
}
}
// Read the current values of the pots, called from the loop.
void readPots ()
{
tempo = (analogRead (AnalogInTempo) * 1.9);
duration = (analogRead (AnalogInDuration));
}
// Read the current values of the switches and
// if pressed, replace the switch's slot frequency
// by reading the frequency pot.
void readSwitches()
{
// reset last pushed button number
lastPushedStep = -1;

// check switch 0, if pressed, get the current freq into step 0, etc. etc.
if (digitalRead (DigitalInSwitch0) == HIGH)
{
steps[0] = analogRead(AnalogInFrequency);
lastPushedStep = 1;
}

else if (digitalRead (DigitalInSwitch1) == HIGH)
{
steps[1] = analogRead(AnalogInFrequency);
lastPushedStep = 2;
}

else if (digitalRead (DigitalInSwitch2) == HIGH)
{
steps[2] = analogRead(AnalogInFrequency);
lastPushedStep = 3;
}
else if (digitalRead (DigitalInSwitch3) == HIGH)
{
steps[3] = analogRead(AnalogInFrequency);
lastPushedStep = 4;
}
else if (digitalRead (DigitalInSwitch4) == HIGH)
{
steps[4] = analogRead(AnalogInFrequency);
lastPushedStep = 5;
}
else if (digitalRead (DigitalInSwitch5) == HIGH)
{
steps[5] = analogRead(AnalogInFrequency);
lastPushedStep = 6;
}
else if (digitalRead (DigitalInSwitch6) == HIGH)
{
steps[6] = analogRead(AnalogInFrequency);
lastPushedStep = 7;
}
else if (digitalRead (DigitalInSwitch7) == HIGH)
{
steps[7] = analogRead(AnalogInFrequency);
lastPushedStep = 8;
}
}


//freqout code by Paul Badger
// freq - frequency value
// t - time duration of tone
void freqout(int freq, int t)
{
int hperiod; //calculate 1/2 period in us
long cycles, i;

// subtract 7 us to make up for digitalWrite overhead - determined empirically
hperiod = (500000 / ((freq - 7) * pitchval));

// calculate cycles
cycles = ((long)freq * (long)t) / 1000; // calculate cycles
for (i=0; i<= cycles; i++)
{ // play note for t ms
digitalWrite(DigitalOutSignal, HIGH);
delayMicroseconds(hperiod);
digitalWrite(DigitalOutSignal, LOW);
delayMicroseconds(hperiod - 1); // - 1 to make up for fractional microsecond in digitaWrite overhead
}
}

―――――――――――――――――――――――――――

(3)実行

さあ、どうでしょう



操作がグダグダ・・・

音がちょっと単調ですが、ステップシーケンサーっぽくなってます

シンセとはまた違った面白さですが・・・思ったように操作できません・・・orz

あと、なんか変だなと思ってたんですが、LED表示が無いのでどのボタンの音がなっているのかわかりにくい

次回はこれを筐体に入れてみます

ではまた〜


【永久保証付き】Arduino Uno

新品価格
¥3,240から


Raspberry Pi3 Model B ボード&ケースセット (Element14版, Clear)-Physical Computing Lab

新品価格
¥5,780から


Arduinoをはじめよう 第3版 (Make:PROJECTS)

新品価格
¥2,160から


Arduinoをはじめよう 互換キット UNO R3対応互換ボード 初心者専用実験キット 基本部品セット20 in 1 Arduino sidekick basic kit

新品価格
¥3,780から


Arduinoをはじめようキット

新品価格
¥4,310から


Arduino エントリーキット(Uno版)- Physical Computing Lab

新品価格
¥4,320から


タミヤ 楽しい工作シリーズ No.216 3ch RCロボット製作セット 70216

新品価格
¥6,327から


エレキット 水圧式ロボットアーム MR-9105

新品価格
¥4,560から


エレキット バトルタイタン2 MR-9101R

新品価格
¥3,163から


世界最小★OZO-010102-0102 World's Smallest SMART Robot - Dual Pack, 1 Crystal White & 1 Titanium Black 2 Bonus Limited-Edition Skins スマートロボット Ozobot社【並行輸入】

新品価格
¥6,000から


タミヤ 楽しい工作シリーズ No.211 アームクローラー工作セット 70211

新品価格
¥1,345から


タミヤ 楽しい工作シリーズ No.97 ツインモーターギヤーボックス (70097)

新品価格
¥587から


タミヤ 楽しい工作シリーズ No.106 4チャンネル・リモコンボックス (70106)

新品価格
¥1,118から


posted by riserobo: at 19:40| Comment(0) | TrackBack(0) | Auduino

2018年07月17日

【番外編6】Simple_Four-Step_Sequencer (S4SS) / ミント缶

Simple_Four-Step_Sequencer

前回Simple_Two-Step_SequencerというArduinoシンセを少し変えてSimple_Two-Step_Sequencerx2Simple_Five-Step_Sequencerというのにしてみた

これをAuduino_v5と同じようにミント缶に入れようと思ったのだけどスペース的にちょっと厳しい

それでSimple_Five-Step_Sequencerからオシレーターを1つ減らしてSimple_Four-Step_Sequencer (S4SS)をつくる
S4SS / ミント缶

パーツはArduino_v5 / ミント缶とほとんど同じだけどアンプユニットがない分だけ楽にできるはず

今回は電源スイッチとオーディオジャックも蓋につけたい

ちなみにスケッチはSimple_Five-Step_Sequencerのものをそのまま使って5つ目のオシレーター用ノブが無いだけ

(1)パーツ配置

パーツ
  1. ミント缶 x1
  2. Arduino NANO x1
  3. 19kΩ小型ポテンショメーター x6
  4. 12v電池+ケース x1
  5. ユニバーサル基板 x1
  6. 5ピン ステレオオーディオジャック x1
  7. トグルスイッチ x1
  8. 3mm LED x1
  9. 8Ω 2W スピーカー+スピーカーグリル x1

パーツの配置はこんな感じ

IMG_0047.jpg

(2)配線

前回のブレッドボードテストを元にユニバーサル基板に配線しました
上面
IMG_0035.jpg

下面
IMG_0036.jpg

(3)組み立て

では、ミント缶に組み入れます



できましたっっ

IMG_0031.jpg

Auduino_v5と区別がつきにくい・・・

ん〜、今回オシレーター1つ減らしたけど・・・やっぱりフルバーションも作ろっかな〜

ではまた〜


【永久保証付き】Arduino Uno

新品価格
¥3,240から


Raspberry Pi3 Model B ボード&ケースセット (Element14版, Clear)-Physical Computing Lab

新品価格
¥5,780から


Arduinoをはじめよう 第3版 (Make:PROJECTS)

新品価格
¥2,160から


Arduinoをはじめよう 互換キット UNO R3対応互換ボード 初心者専用実験キット 基本部品セット20 in 1 Arduino sidekick basic kit

新品価格
¥3,780から


Arduinoをはじめようキット

新品価格
¥4,310から


Arduino エントリーキット(Uno版)- Physical Computing Lab

新品価格
¥4,320から


タミヤ 楽しい工作シリーズ No.216 3ch RCロボット製作セット 70216

新品価格
¥6,327から


エレキット 水圧式ロボットアーム MR-9105

新品価格
¥4,560から


エレキット バトルタイタン2 MR-9101R

新品価格
¥3,163から


世界最小★OZO-010102-0102 World's Smallest SMART Robot - Dual Pack, 1 Crystal White & 1 Titanium Black 2 Bonus Limited-Edition Skins スマートロボット Ozobot社【並行輸入】

新品価格
¥6,000から


タミヤ 楽しい工作シリーズ No.211 アームクローラー工作セット 70211

新品価格
¥1,345から


タミヤ 楽しい工作シリーズ No.97 ツインモーターギヤーボックス (70097)

新品価格
¥587から


タミヤ 楽しい工作シリーズ No.106 4チャンネル・リモコンボックス (70106)

新品価格
¥1,118から


posted by riserobo: at 19:36| Comment(0) | TrackBack(0) | Auduino

2018年07月10日

【番外編5】Simple_Two-Step_Sequencer (STSS) / ブレッドボード

Workshop: Basic Arduino Square-Wave Synth

前回までAuduino_v5を少し変えたりしてみたけど、これ以上は似たようなアイデアしかない

ほかのArduinoシンセも聴きたいので別のものを作ってみる

ググってたら"Workshop: Basic Arduino Square-Wave Synth"というサイトを見つけた

スクリーンショット 2018-06-26 14.53.28.png

何かのWorkshopネタらしいのでやりやすいかなと思ったけど、このシンセの音情報が見つけられなかったのでどんな音が出るのかわからない

で、とりあえずつくってから考える
1. Simple_Two-Step_Sequencer (STSS)

(1)配線

まずはブレッドボードでの配線

IMG_0015.jpg

Fritzingも

スクリーンショット 2018-06-26 9.07.35.png

今回、ポテンショは10kΩを使ってます

(2)スケッチ

スケッチは"Workshop: Basic Arduino Square-Wave Synth"からコピペ

Simple_Two-Step_Sequencer (STSS)
―――――――(Simple_Two-Step_Sequencer)―――――――
/*
6: Simple Two-Step Sequencer

This project combines pretty much everything from the previous tutorials.
It involves two oscillators, a status led, and tempo and volume pots.

*/

int speakerPin = 3; //connect speaker to pin 3
int ledPin = 11; //we'll use this pin for our status led
int oscillator1Pin = 0; //we can set frequency for first step here...
int oscillator2Pin = 1; //... and frequency for step 2 on this pin
int tempoPin = 2; //read tempo pot here

/*
The pinState variable checks if we are outputting a sound.
By default we can set it to LOW - meaning "off".
*/
int pinState = LOW;

long previousMicros; //count microSeconds to control frequency
int frequency; //variable to set frequency

long previousMillis; //count milliSeconds to control tempo
int tempo = 120; //default tempo is 120BPM

void setup(){
Serial.begin(9600);
pinMode(speakerPin, OUTPUT);
}

void loop(){

//read from our analog pins and set our frequency limits
float oscillator1 = analogRead(oscillator1Pin);
oscillator1 = map(oscillator1, 0, 1023, 200, 2000);

float oscillator2 = analogRead(oscillator2Pin);
oscillator2 = map(oscillator2, 0, 1023, 200, 2000);

//read and set tempo limits
float tempo = analogRead(tempoPin);
tempo = map(tempo, 0, 1023, 60, 1000);

//algorithm to convert tempo into BPM
float interval = (1000/tempo)*60;

/*
We can't use the delay function in this case,
as it will freeze the sketch and disrupt the
oscillators.
Instead we use a method that counts milliSeconds,
compares it to our BPM, and switches between which
oscillator should be in use.
*/

//oscillator1
if(millis()-previousMillis > interval/2){
playTone(speakerPin, oscillator1, interval/2);
analogWrite(ledPin, LOW);
}
//oscillator 2
if(millis()-previousMillis < interval/2){
playTone(speakerPin, oscillator2, interval/2);
analogWrite(ledPin, tempo/4);
}
//One cycle completed: reset our counter!
if(millis()-previousMillis > interval){
previousMillis = millis();
}
}

/*
We use the same method here as above to
switch our outputPin on and off without having
to use delay() and thus keep everything running
smoothly.
*/

void playTone(int outputPin, int frequency, float tempo){

//this bit is new - it makes sure we're calculating the note's frequency correctly
float hperiod = (500000 / frequency) -7;
long cycles = ((frequency*tempo)/1000);
for(long i=0; i<=cycles; i++){
//we use frequency/2 because one LOW + one HIGH = one whole cycle
if(micros() - previousMicros > frequency/2){
previousMicros = micros();
if(pinState == LOW){
pinState = HIGH; //if the pin is already LOW, set it to HIGH
}
else{
pinState = LOW; //otherwise if it's HIGH, set it to LOW
}
digitalWrite(outputPin, pinState); //Write pinState to specified pin
}
}
}

――――――――――――――――――――――――――――

(3)実行

します



なるほど・・・昔のアニメの効果音みたいな音が出てきましたね・・・
思ってたんとちがーうって感じですがこれはこれで

で、これで終わっちゃうと"Workshop: Basic Arduino Square-Wave Synth"の重複情報を無駄に増やしただけなので少し変えます
2. Simple_Two-Step_Sequencerx2 (STSSx2)

Auduino_v5の時に2倍化しましたが今回もします

Arduino UNOには6つのアナログインプットがありますが、STSSはオシレーター2つとテンポ1つで合わせて3つのアナログインプットが使われています

今回はこれをもう1セット付け加えるだけです
というわけで名前はSimple_Two-Step_Sequencerx2

(1)配線

ブレッドボード上での配線はこんな感じ

IMG_0014.jpg
スクリーンショット 2018-06-26 9.06.23.png

(2)スケッチ

スケッチは少し書き足してこんな感じ

Simple_Two-Step_Sequencerx2
―――――(Simple_Two-Step_Sequencerx2 (STSSx2))―――――
/*
6': Simple Two-Step Sequencer x2

This project combines pretty much everything from the previous tutorials.
It involves two oscillators, a status led, and tempo and volume pots.

Changelog:
It involves four oscillators, a status led, and two tempo and volume pots.
*/

int speakerPin = 3; //connect speaker to pin 3
int ledPin = 11; //we'll use this pin for our status led
int oscillator1Pin = 0; //we can set frequency for first step here...
int oscillator2Pin = 1; //... and frequency for step 2 on this pin
int tempoPin1 = 2; //read tempo pot here
int oscillator3Pin = 3; //we can set frequency for first step here...
int oscillator4Pin = 4; //... and frequency for step 2 on this pin
int tempoPin2 = 5; //read tempo pot here

/*
The pinState variable checks if we are outputting a sound.
By default we can set it to LOW - meaning "off".
*/
int pinState = LOW;

long previousMicros; //count microSeconds to control frequency
int frequency; //variable to set frequency

long previousMillis; //count milliSeconds to control tempo
int tempo = 120; //default tempo is 120BPM

void setup(){
Serial.begin(9600);
pinMode(speakerPin, OUTPUT);
}

void loop(){

//read from our analog pins and set our frequency limits
float oscillator1 = analogRead(oscillator1Pin);
oscillator1 = map(oscillator1, 0, 1023, 200, 2000);

float oscillator2 = analogRead(oscillator2Pin);
oscillator2 = map(oscillator2, 0, 1023, 200, 2000);

//read and set tempo1 limits
float tempo1 = analogRead(tempoPin1);
tempo1 = map(tempo1, 0, 1023, 60, 1000);

//algorithm to convert tempo into BPM
float interval1 = (1000/tempo1)*60;

//read from our analog pins and set our frequency limits
float oscillator3 = analogRead(oscillator3Pin);
oscillator3 = map(oscillator3, 0, 1023, 200, 2000);

float oscillator4 = analogRead(oscillator4Pin);
oscillator4 = map(oscillator4, 0, 1023, 200, 2000);

//read and set tempo2 limits
float tempo2 = analogRead(tempoPin2);
tempo2 = map(tempo2, 0, 1023, 60, 1000);

//algorithm to convert tempo into BPM
float interval2 = (1000/tempo2)*60;

/*
We can't use the delay function in this case,
as it will freeze the sketch and disrupt the
oscillators.
Instead we use a method that counts milliSeconds,
compares it to our BPM, and switches between which
oscillator should be in use.
*/

//oscillator1
if(millis()-previousMillis > interval1/2){
playTone(speakerPin, oscillator1, interval1/2);
analogWrite(ledPin, LOW);
}
//oscillator2
if(millis()-previousMillis < interval1/2){
playTone(speakerPin, oscillator2, interval1/2);
analogWrite(ledPin, tempo1/4);
}
//One cycle completed: reset our counter!
if(millis()-previousMillis > interval1){
previousMillis = millis();
}
//oscillator3
if(millis()-previousMillis > interval2/2){
playTone(speakerPin, oscillator3, interval2/2);
analogWrite(ledPin, LOW);
}
//oscillator4
if(millis()-previousMillis < interval2/2){
playTone(speakerPin, oscillator4, interval2/2);
analogWrite(ledPin, tempo2/4);
}
//One cycle completed: reset our counter!
if(millis()-previousMillis > interval2){
previousMillis = millis();
}
}

/*
We use the same method here as above to
switch our outputPin on and off without having
to use delay() and thus keep everything running
smoothly.
*/

void playTone(int outputPin, int frequency, float tempo){

//this bit is new - it makes sure we're calculating the note's frequency correctly
float hperiod = (500000 / frequency) -7;
long cycles = ((frequency*tempo)/1000);
for(long i=0; i<=cycles; i++){
//we use frequency/2 because one LOW + one HIGH = one whole cycle
if(micros() - previousMicros > frequency/2){
previousMicros = micros();
if(pinState == LOW){
pinState = HIGH; //if the pin is already LOW, set it to HIGH
}
else{
pinState = LOW; //otherwise if it's HIGH, set it to LOW
}
digitalWrite(outputPin, pinState); //Write pinState to specified pin
}
}
}

―――――――――――――――――――――――――――――

(3)実行

さて音の変化は2倍になったんでしょうか



う〜んなんとも・・・表現が広がった気はするけど2倍まではいかないかな

パラメーターをもう少しいじってみたほうがいいかな

とりあえずもう1つの案もやってみる
3. Simple_Five-Step_Sequencer (SFSS)

オシレーターのフリークエンシー調節に使ってるポテンショメーターの数を5つに増やしてみる

オシレーター5つとテンポ1つで6つのアナログインプットを埋めるという案

(1)配線

配線は上記2. Simple_Two-Step_Sequencerx2 (STSSx2)と同じ

(2)スケッチ

スケッチをこんな感じにして

Simple_Five-Step_Sequencer
―――――――(Simple_FIve-Step_Sequencer)―――――――
/*
6'': Simple Five-Step Sequencer

This project combines pretty much everything from the previous tutorials.
It involves two oscillators, a status led, and tempo and volume pots.

Changelog:
It involves five oscillators, a status led, and tempo and volume pots.
*/

int speakerPin = 3; //connect speaker to pin 3
int ledPin = 11; //we'll use this pin for our status led
int oscillator1Pin = 0; //we can set frequency for first step here...
int oscillator2Pin = 1; //... and frequency for step 2 on this pin
int oscillator3Pin = 2; //... and frequency for step 3 on this pin
int oscillator4Pin = 3; //... and frequency for step 4 on this pin
int oscillator5Pin = 4; //... and frequency for step 5 on this pin
int tempoPin = 5; //read tempo pot here

/*
The pinState variable checks if we are outputting a sound.
By default we can set it to LOW - meaning "off".
*/
int pinState = LOW;

long previousMicros; //count microSeconds to control frequency
int frequency; //variable to set frequency

long previousMillis; //count milliSeconds to control tempo
int tempo = 120; //default tempo is 120BPM

void setup(){
Serial.begin(9600);
pinMode(speakerPin, OUTPUT);
}

void loop(){

//read from our analog pins and set our frequency limits
float oscillator1 = analogRead(oscillator1Pin);
oscillator1 = map(oscillator1, 0, 1023, 200, 2000);

float oscillator2 = analogRead(oscillator2Pin);
oscillator2 = map(oscillator2, 0, 1023, 200, 2000);

float oscillator3 = analogRead(oscillator3Pin);
oscillator3 = map(oscillator3, 0, 1023, 200, 2000);

float oscillator4 = analogRead(oscillator4Pin);
oscillator4 = map(oscillator4, 0, 1023, 200, 2000);

float oscillator5 = analogRead(oscillator5Pin);
oscillator5 = map(oscillator5, 0, 1023, 200, 2000);

//read and set tempo limits
float tempo = analogRead(tempoPin);
tempo = map(tempo, 0, 1023, 60, 1000);

//algorithm to convert tempo into BPM
float interval = (1000/tempo)*60;

/*
We can't use the delay function in this case,
as it will freeze the sketch and disrupt the
oscillators.
Instead we use a method that counts milliSeconds,
compares it to our BPM, and switches between which
oscillator should be in use.
*/

//oscillator1
if(millis()-previousMillis > interval/2){
playTone(speakerPin, oscillator1, interval/2);
analogWrite(ledPin, LOW);
}
//oscillator 2
if(millis()-previousMillis < interval/2){
playTone(speakerPin, oscillator2, interval/2);
analogWrite(ledPin, tempo/2);
}
//oscillator 3
if(millis()-previousMillis > interval/3){
playTone(speakerPin, oscillator3, interval/3);
analogWrite(ledPin, tempo/3);
}
//oscillator 4
if(millis()-previousMillis < interval/3){
playTone(speakerPin, oscillator4, interval/3);
analogWrite(ledPin, tempo/4);
}
//oscillator 5
if(millis()-previousMillis < interval/5){
playTone(speakerPin, oscillator5, interval/5);
analogWrite(ledPin, tempo/5);
}
//One cycle completed: reset our counter!
if(millis()-previousMillis > interval){
previousMillis = millis();
}
}

/*
We use the same method here as above to
switch our outputPin on and off without having
to use delay() and thus keep everything running
smoothly.
*/

void playTone(int outputPin, int frequency, float tempo){

//this bit is new - it makes sure we're calculating the note's frequency correctly
float hperiod = (500000 / frequency) -7;
long cycles = ((frequency*tempo)/1000);
for(long i=0; i<=cycles; i++){
//we use frequency/2 because one LOW + one HIGH = one whole cycle
if(micros() - previousMicros > frequency/2){
previousMicros = micros();
if(pinState == LOW){
pinState = HIGH; //if the pin is already LOW, set it to HIGH
}
else{
pinState = LOW; //otherwise if it's HIGH, set it to LOW
}
digitalWrite(outputPin, pinState); //Write pinState to specified pin
}
}
}

――――――――――――――――――――――――――――

(3)実行

これでもっとガチャガチャした音が出てくれればいいんだけど・・・



い、いけてるのか?

まあ、子供騙しなのでこれはこの辺で

で、せっかくなので次回このうちどれかを筐体に入れようかなと思います

ではまた〜


【永久保証付き】Arduino Uno

新品価格
¥3,240から


Raspberry Pi3 Model B ボード&ケースセット (Element14版, Clear)-Physical Computing Lab

新品価格
¥5,780から


Arduinoをはじめよう 第3版 (Make:PROJECTS)

新品価格
¥2,160から


Arduinoをはじめよう 互換キット UNO R3対応互換ボード 初心者専用実験キット 基本部品セット20 in 1 Arduino sidekick basic kit

新品価格
¥3,780から


Arduinoをはじめようキット

新品価格
¥4,310から


Arduino エントリーキット(Uno版)- Physical Computing Lab

新品価格
¥4,320から


タミヤ 楽しい工作シリーズ No.216 3ch RCロボット製作セット 70216

新品価格
¥6,327から


エレキット 水圧式ロボットアーム MR-9105

新品価格
¥4,560から


エレキット バトルタイタン2 MR-9101R

新品価格
¥3,163から


世界最小★OZO-010102-0102 World's Smallest SMART Robot - Dual Pack, 1 Crystal White & 1 Titanium Black 2 Bonus Limited-Edition Skins スマートロボット Ozobot社【並行輸入】

新品価格
¥6,000から


タミヤ 楽しい工作シリーズ No.211 アームクローラー工作セット 70211

新品価格
¥1,345から


タミヤ 楽しい工作シリーズ No.97 ツインモーターギヤーボックス (70097)

新品価格
¥587から


タミヤ 楽しい工作シリーズ No.106 4チャンネル・リモコンボックス (70106)

新品価格
¥1,118から


posted by riserobo: at 14:56| Comment(0) | TrackBack(0) | Auduino

2018年06月26日

【番外編3】Auduino_v5+DIPS / ブレッドボード

基板用ポテンショメーターはブレッドボードから外れやすい

前回のAuduino_v5をミント缶に実装する前に基板用ポテンショメーターを使ってブレッドボード上でAuduino_v5を組んで動作確認した



この基板用ポテンショは足がブレッドボードから外れやすく、外れると出音が変わることがある

どの足の信号がどんな音の変化に影響しているのかを知りたくてジャンパー線を1本ずつ外してみたりするとほとんどの足で違った音の変化があるように感じる

とりあえず音の変化のバリエーションが多いのは面白いというだけで
「それぞれの入出力をディップスイッチで切り替えられるAuduino_v5」(Auduino_v5+DIP Switch (DIPS))を作ってみようと思った
Auduino_v5+DIPS / ブレッドボード

ブレッドボードで作ってみる

(1)配線

配線はこんな感じ

IMG_0022.jpg

Auduino_v5+DIPS.png
(Fritzingに3極ディップスイッチがなかったので8極で代用)

(2)スケッチ

スケッチはauduino_v5と同じ

(3)実行

では実行してディップスイッチをいじってみます



一応できているかな

ディップスイッチを使わなくても、つまみをグリグリ動かすことで同じような音が出そうですが、ディップスイッチをいじった瞬間に音が変化するのはつまみとは違った面白さがあります

今回はここまで

ではまた〜


【永久保証付き】Arduino Uno

新品価格
¥3,240から


Raspberry Pi3 Model B ボード&ケースセット (Element14版, Clear)-Physical Computing Lab

新品価格
¥5,780から


Arduinoをはじめよう 第3版 (Make:PROJECTS)

新品価格
¥2,160から


Arduinoをはじめよう 互換キット UNO R3対応互換ボード 初心者専用実験キット 基本部品セット20 in 1 Arduino sidekick basic kit

新品価格
¥3,780から


Arduinoをはじめようキット

新品価格
¥4,310から


Arduino エントリーキット(Uno版)- Physical Computing Lab

新品価格
¥4,320から


タミヤ 楽しい工作シリーズ No.216 3ch RCロボット製作セット 70216

新品価格
¥6,327から


エレキット 水圧式ロボットアーム MR-9105

新品価格
¥4,560から


エレキット バトルタイタン2 MR-9101R

新品価格
¥3,163から


世界最小★OZO-010102-0102 World's Smallest SMART Robot - Dual Pack, 1 Crystal White & 1 Titanium Black 2 Bonus Limited-Edition Skins スマートロボット Ozobot社【並行輸入】

新品価格
¥6,000から


タミヤ 楽しい工作シリーズ No.211 アームクローラー工作セット 70211

新品価格
¥1,345から


タミヤ 楽しい工作シリーズ No.97 ツインモーターギヤーボックス (70097)

新品価格
¥587から


タミヤ 楽しい工作シリーズ No.106 4チャンネル・リモコンボックス (70106)

新品価格
¥1,118から


posted by riserobo: at 08:21| Comment(0) | TrackBack(0) | Auduino

2018年06月19日

【番外編2】Auduino_v5 / ミント缶

パーツ再考

前回、ブレッドボード上でauduino_v5を組んで音を出した
これをALTOIDS缶に組み込みたいけど・・・

IMG_0008-Edit.jpg

9v電池を使おうとすると・・・ALTOIDS缶の大きさが・・・これは全部は入らないんじゃ・・仮置きしてみると

IMG_0009-Edit.jpg

配線を考えるとちょっと入りそうにないので、いくつかパーツを変更することにしました

ケースを大きくするのが一番簡単だということには気がつかないことにします

(パーツ変更)
1. ALTOIDS缶は加工がしやすいように無地のもの
2. Arduino UNOは小さいArduino NANO
3. ポテンショメーター小型のもの
4. 9v電池は小さい12v電池
5. 8Ω 0.5W スピーカーを小型の8Ω 1W スピーカー
6. 4極オーディオジャック実装済み基板を差し込み口固定用ネジがきってある5ピン ステレオオーディオジャック


IMG_0010.jpg

変更したパーツで仮置きしてみました

IMG_0011.jpg

これでいけるはず
実装

実装するのを一回失敗してるので全体の流れを先に示すと

(1)(失敗)配線取り回し
はじめ蓋一体型のミント缶に配線取り回しで作ったけど何回か蓋の開け閉めをしたら断線、ショートしてArduino nanoが壊れた(泣)

(2)(成功)ユニバーサル基板
配線取り回しをやめて、できるだけユニバーサル基板に載せ、蓋の開け閉めを減らすために電源スイッチとLEDをつけた
(1)配線取り回し(Auduino_v5_1st)(失敗)

ALTOIDSサイズ缶の穴あけと配線の半田付けまでをして組み立てて・・・

IMG_0013.jpg

蓋を閉めて音出しをして・・・なんか調子がおかしくなって・・・配線が外れてて・・・音出しをして・・・蓋を閉めて・・・音がしなくなって・・・配線が切れてて・・・結線やり直して・・・蓋をして音が出なくて煙が出て・・・あれ?っと思ったらArduino NANOが反応しなくなって・・・ダメだこりゃ

Arduino NANOが逝ってしまいました(痛恨)
ワイヤーの選択を誤ったな・・・orz

IMG_0012.jpg

この方法は難しいので新しく作り直します
(2)ユニバーサル基板(Auduino_v5_2nd)

Auduino_v5_1stからの改善案

(問題点と改善点)
@ 狭いスペースでの配線取り回しと蓋の開け閉めでケーブルにストレスがかかって接触不良・断線・ショートしてnanoが逝ってしまった
 ⇨ できるだけ基板実装タイプにする
A ポテンショメーターつまみ間の距離が狭く操作性が悪かった
 ⇨ つまみ位置間隔をできるだけ広めにとる
B 蝶番蓋の開け方で配線にストレスがかかる
 ⇨ 蓋を取り外せるタイプにして蓋の開け方に自由度を持たせる
C スピーカー穴のデザインがいまいち&穴あけ面倒
 ⇨ スピーカー穴のデザインを変える
D 蓋を閉めると電源のON/OFFや確認ができない
 ⇨ 電源スイッチとLEDインジケーターをつける

という感じでパーツを作りました

上面
IMG_0045.jpg

下面
IMG_0044.jpg

ミント缶に入れる前に一度テストしてみるとスピーカーでは気にならなかったノイズがイヤホンだと気になって、ボリュームを最小にすると「シー」って音と低い「ムー」みたいな音が聞こえたので出力に47Ωの抵抗をかませて抑えた

ノイズを完全に抑えようとするとスピーカーからの出力が下がるし、低すぎるとノイズがきになるのでその間で47Ωにしました

組み立てと動作テスト

ミント缶に組み入れます



できました!

IMG_0037.jpg
完成

これで完成ですっっっ

ではまた〜



【永久保証付き】Arduino Uno

新品価格
¥3,240から


Raspberry Pi3 Model B ボード&ケースセット (Element14版, Clear)-Physical Computing Lab

新品価格
¥5,780から


Arduinoをはじめよう 第3版 (Make:PROJECTS)

新品価格
¥2,160から


Arduinoをはじめよう 互換キット UNO R3対応互換ボード 初心者専用実験キット 基本部品セット20 in 1 Arduino sidekick basic kit

新品価格
¥3,780から


Arduinoをはじめようキット

新品価格
¥4,310から


Arduino エントリーキット(Uno版)- Physical Computing Lab

新品価格
¥4,320から


タミヤ 楽しい工作シリーズ No.216 3ch RCロボット製作セット 70216

新品価格
¥6,327から


エレキット 水圧式ロボットアーム MR-9105

新品価格
¥4,560から


エレキット バトルタイタン2 MR-9101R

新品価格
¥3,163から


世界最小★OZO-010102-0102 World's Smallest SMART Robot - Dual Pack, 1 Crystal White & 1 Titanium Black 2 Bonus Limited-Edition Skins スマートロボット Ozobot社【並行輸入】

新品価格
¥6,000から


タミヤ 楽しい工作シリーズ No.211 アームクローラー工作セット 70211

新品価格
¥1,345から


タミヤ 楽しい工作シリーズ No.97 ツインモーターギヤーボックス (70097)

新品価格
¥587から


タミヤ 楽しい工作シリーズ No.106 4チャンネル・リモコンボックス (70106)

新品価格
¥1,118から


posted by riserobo: at 11:16| Comment(0) | TrackBack(0) | Auduino

2018年06月12日

【番外編1】Auduino_v5 / ブレッドボード

Auduinoって?

ロボットのためにArduinoのことを調べているときに"Auduino"というのを見かけた

AuduinoはArduinoを使ったシンセサイザーのようなもののよう
ロボット作りと直接関係ないけど寄り道は楽しい

というわけで番外編

今回は、第6回「シンプルなのに出音がすごいシンセサイザ - Auduino入門」を参考に「Auduino_v5」を作ります

スクリーンショット 2018-06-11 21.57.47.png
この記事は・・・(2009年 7月 16日)のものなんですかね・・・結構前ですね・・・知らんかった

では、やってみます
ブレッドボードでAuduino

(1)配線

ブレッドボードを使って組んでみます

(材料)
  1. Arduino UNO (互換品)x1
  2. Arduino UNO付属のUSBケーブル x1
  3. B10Kポテンショメーター x5
  4. 0.5Wスピーカー x1
  5. ブレッドボード x1
  6. ジャンパワイヤー x必要数


IMG_0001-Edit.jpg

そんなに複雑じゃ無いのでブレッドボードいらないんですが・・・

IMG_0002-Edit.jpg

一応できました

写真だとわかりにくいのでFritzingも置いて

スクリーンショット 2018-06-12 9.40.32.png

(2)スケッチ

スケッチは第6回「シンプルなのに出音がすごいシンセサイザ - Auduino入門」の記事中に紹介されているtinker.it のリスト中のauduino_v5.pdeをダウンロードしてAuduino IDEで開きます

スクリーンショット 2018-06-11 22.02.26.png

auduino_v5
――――――――――(auduino_v5)――――――――――
// Auduino, the Lo-Fi granular synthesiser
//
// by Peter Knight, Tinker.it http://tinker.it
//
// Help: http://code.google.com/p/tinkerit/wiki/Auduino
// More help: http://groups.google.com/group/auduino
//
// Analog in 0: Grain 1 pitch
// Analog in 1: Grain 2 decay
// Analog in 2: Grain 1 decay
// Analog in 3: Grain 2 pitch
// Analog in 4: Grain repetition frequency
//
// Digital 3: Audio out (Digital 11 on ATmega8)
//
// Changelog:
// 19 Nov 2008: Added support for ATmega8 boards
// 21 Mar 2009: Added support for ATmega328 boards
// 7 Apr 2009: Fixed interrupt vector for ATmega328 boards
// 8 Apr 2009: Added support for ATmega1280 boards (Arduino Mega)

#include
#include

uint16_t syncPhaseAcc;
uint16_t syncPhaseInc;
uint16_t grainPhaseAcc;
uint16_t grainPhaseInc;
uint16_t grainAmp;
uint8_t grainDecay;
uint16_t grain2PhaseAcc;
uint16_t grain2PhaseInc;
uint16_t grain2Amp;
uint8_t grain2Decay;

// Map Analogue channels
#define SYNC_CONTROL (4)
#define GRAIN_FREQ_CONTROL (0)
#define GRAIN_DECAY_CONTROL (2)
#define GRAIN2_FREQ_CONTROL (3)
#define GRAIN2_DECAY_CONTROL (1)


// Changing these will also requires rewriting audioOn()

#if defined(__AVR_ATmega8__)
//
// On old ATmega8 boards.
// Output is on pin 11
//
#define LED_PIN 13
#define LED_PORT PORTB
#define LED_BIT 5
#define PWM_PIN 11
#define PWM_VALUE OCR2
#define PWM_INTERRUPT TIMER2_OVF_vect
#elif defined(__AVR_ATmega1280__)
//
// On the Arduino Mega
// Output is on pin 3
//
#define LED_PIN 13
#define LED_PORT PORTB
#define LED_BIT 7
#define PWM_PIN 3
#define PWM_VALUE OCR3C
#define PWM_INTERRUPT TIMER3_OVF_vect
#else
//
// For modern ATmega168 and ATmega328 boards
// Output is on pin 3
//
#define PWM_PIN 3
#define PWM_VALUE OCR2B
#define LED_PIN 13
#define LED_PORT PORTB
#define LED_BIT 5
#define PWM_INTERRUPT TIMER2_OVF_vect
#endif

// Smooth logarithmic mapping
//
uint16_t antilogTable[] = {
64830,64132,63441,62757,62081,61413,60751,60097,59449,58809,58176,57549,56929,56316,55709,55109,
54515,53928,53347,52773,52204,51642,51085,50535,49991,49452,48920,48393,47871,47356,46846,46341,
45842,45348,44859,44376,43898,43425,42958,42495,42037,41584,41136,40693,40255,39821,39392,38968,
38548,38133,37722,37316,36914,36516,36123,35734,35349,34968,34591,34219,33850,33486,33125,32768
};
uint16_t mapPhaseInc(uint16_t input) {
return (antilogTable[input & 0x3f]) >> (input >> 6);
}

// Stepped chromatic mapping
//
uint16_t midiTable[] = {
17,18,19,20,22,23,24,26,27,29,31,32,34,36,38,41,43,46,48,51,54,58,61,65,69,73,
77,82,86,92,97,103,109,115,122,129,137,145,154,163,173,183,194,206,218,231,
244,259,274,291,308,326,346,366,388,411,435,461,489,518,549,581,616,652,691,
732,776,822,871,923,978,1036,1097,1163,1232,1305,1383,1465,1552,1644,1742,
1845,1955,2071,2195,2325,2463,2610,2765,2930,3104,3288,3484,3691,3910,4143,
4389,4650,4927,5220,5530,5859,6207,6577,6968,7382,7821,8286,8779,9301,9854,
10440,11060,11718,12415,13153,13935,14764,15642,16572,17557,18601,19708,20879,
22121,23436,24830,26306
};
uint16_t mapMidi(uint16_t input) {
return (midiTable[(1023-input) >> 3]);
}

// Stepped Pentatonic mapping
//
uint16_t pentatonicTable[54] = {
0,19,22,26,29,32,38,43,51,58,65,77,86,103,115,129,154,173,206,231,259,308,346,
411,461,518,616,691,822,923,1036,1232,1383,1644,1845,2071,2463,2765,3288,
3691,4143,4927,5530,6577,7382,8286,9854,11060,13153,14764,16572,19708,22121,26306
};

uint16_t mapPentatonic(uint16_t input) {
uint8_t value = (1023-input) / (1024/53);
return (pentatonicTable[value]);
}


void audioOn() {
#if defined(__AVR_ATmega8__)
// ATmega8 has different registers
TCCR2 = _BV(WGM20) | _BV(COM21) | _BV(CS20);
TIMSK = _BV(TOIE2);
#elif defined(__AVR_ATmega1280__)
TCCR3A = _BV(COM3C1) | _BV(WGM30);
TCCR3B = _BV(CS30);
TIMSK3 = _BV(TOIE3);
#else
// Set up PWM to 31.25kHz, phase accurate
TCCR2A = _BV(COM2B1) | _BV(WGM20);
TCCR2B = _BV(CS20);
TIMSK2 = _BV(TOIE2);
#endif
}


void setup() {
pinMode(PWM_PIN,OUTPUT);
audioOn();
pinMode(LED_PIN,OUTPUT);
}

void loop() {
// The loop is pretty simple - it just updates the parameters for the oscillators.
//
// Avoid using any functions that make extensive use of interrupts, or turn interrupts off.
// They will cause clicks and poops in the audio.

// Smooth frequency mapping
//syncPhaseInc = mapPhaseInc(analogRead(SYNC_CONTROL)) / 4;

// Stepped mapping to MIDI notes: C, Db, D, Eb, E, F...
//syncPhaseInc = mapMidi(analogRead(SYNC_CONTROL));

// Stepped pentatonic mapping: D, E, G, A, B
syncPhaseInc = mapPentatonic(analogRead(SYNC_CONTROL));

grainPhaseInc = mapPhaseInc(analogRead(GRAIN_FREQ_CONTROL)) / 2;
grainDecay = analogRead(GRAIN_DECAY_CONTROL) / 8;
grain2PhaseInc = mapPhaseInc(analogRead(GRAIN2_FREQ_CONTROL)) / 2;
grain2Decay = analogRead(GRAIN2_DECAY_CONTROL) / 4;
}

SIGNAL(PWM_INTERRUPT)
{
uint8_t value;
uint16_t output;

syncPhaseAcc += syncPhaseInc;
if (syncPhaseAcc < syncPhaseInc) {
// Time to start the next grain
grainPhaseAcc = 0;
grainAmp = 0x7fff;
grain2PhaseAcc = 0;
grain2Amp = 0x7fff;
LED_PORT ^= 1 << LED_BIT; // Faster than using digitalWrite
}

// Increment the phase of the grain oscillators
grainPhaseAcc += grainPhaseInc;
grain2PhaseAcc += grain2PhaseInc;

// Convert phase into a triangle wave
value = (grainPhaseAcc >> 7) & 0xff;
if (grainPhaseAcc & 0x8000) value = ~value;
// Multiply by current grain amplitude to get sample
output = value * (grainAmp >> 8);

// Repeat for second grain
value = (grain2PhaseAcc >> 7) & 0xff;
if (grain2PhaseAcc & 0x8000) value = ~value;
output += value * (grain2Amp >> 8);

// Make the grain amplitudes decay by a factor every sample (exponential decay)
grainAmp -= (grainAmp >> 8) * grainDecay;
grain2Amp -= (grain2Amp >> 8) * grain2Decay;

// Scale output to the available range, clipping if necessary
output >>= 9;
if (output > 255) output = 255;

// Output to PWM (this is faster than using analogWrite)
PWM_VALUE = output;
}

―――――――――――――――――――――――――――

(3)実行
(2)のスケッチをArduinoに書き込んで実行します

初めは小さなビープ音しか聴こえなくて、なんか失敗したかなって感じだったんですが、ノブを色々いじってみるとそれなりに音が聴こえるようになりました


ちょっと楽しくていろいろいじって遊んでしまった

でも・・・音が小さいというか・・・小さい音の中にもかすかに音の変化があるというか・・・何かを聴き落としているような・・・

もっと大きなスピーカーに繋ぐとかイヤホンで聴いた方が良いかな?

というわけで、4極オーディオジャック実装済み基板につないでイヤホンで聴いてみます

IMG_0004-Edit.jpg
4極オーディオジャック実装済み基板


イヤホンから出ている音だけでもスピーカーより大きいような・・・
途中イヤホンの左右のつなぎ変えの方法を確かめたりしてます
音が聞こえないところでは耳にイヤホンを入れて聴いてます

イヤホンを耳で聴いたら、耳が痛いくらいの大音量になったけど、音の傾向は変わらず、逆にゲインが大きすぎると耳に良く無さそうで聴きにくい
心持ちビビリノイズが増えているような・・・

これはアンプに繋いでボリューム調節できないとダメなんじゃ・・・オーディオジャック経由でアンプ付きスピーカーに繋ぐしか無いのかな・・・持ち運びできるといいんだが・・・

なんかいいのないかなあってググっててAmazonでボリュームノブのついた小型オーディオアンプボードを見つけたのでつないでみる

IMG_0006-Edit.jpg
小型オーディオアンプボード


小型オーディオアンプボードのスルーホールに直接ジャンパー線をつないで接続しているのでところどころ接触が悪くて音が飛んでます・・・

結果はまあ、いいんじゃないでしょうか
小さな音の変化を拾いやすくなったような気がします

これくらいの構成で一度ケースに組み込んでみようと思います

ではまた〜


【永久保証付き】Arduino Uno

新品価格
¥3,240から


Raspberry Pi3 Model B ボード&ケースセット (Element14版, Clear)-Physical Computing Lab

新品価格
¥5,780から


Arduinoをはじめよう 第3版 (Make:PROJECTS)

新品価格
¥2,160から


Arduinoをはじめよう 互換キット UNO R3対応互換ボード 初心者専用実験キット 基本部品セット20 in 1 Arduino sidekick basic kit

新品価格
¥3,780から


Arduinoをはじめようキット

新品価格
¥4,310から


Arduino エントリーキット(Uno版)- Physical Computing Lab

新品価格
¥4,320から


タミヤ 楽しい工作シリーズ No.216 3ch RCロボット製作セット 70216

新品価格
¥6,327から


エレキット 水圧式ロボットアーム MR-9105

新品価格
¥4,560から


エレキット バトルタイタン2 MR-9101R

新品価格
¥3,163から


世界最小★OZO-010102-0102 World's Smallest SMART Robot - Dual Pack, 1 Crystal White & 1 Titanium Black 2 Bonus Limited-Edition Skins スマートロボット Ozobot社【並行輸入】

新品価格
¥6,000から


タミヤ 楽しい工作シリーズ No.211 アームクローラー工作セット 70211

新品価格
¥1,345から


タミヤ 楽しい工作シリーズ No.97 ツインモーターギヤーボックス (70097)

新品価格
¥587から


タミヤ 楽しい工作シリーズ No.106 4チャンネル・リモコンボックス (70106)

新品価格
¥1,118から


posted by riserobo: at 19:25| Comment(0) | TrackBack(0) | Auduino

2016年09月24日

A6:5 高度な入力と出力:アナログ入出力 LEDランプ作成

アナログ入力+PWM出力 LEDランプ作成

前々回前回、の『Arduinoをはじめよう 第3版』第4章スケッチ入門 ではLEDをデジタル入出力制御しました

第5章 高度な入力と出力ではアナログ入出力LEDランプを作るようです

Arduinoをはじめよう 第3版 (Make:PROJECTS)

新品価格
¥2,160から


  ページ 実行内容                  スケッチ
  051  ゆっくり明滅するLED            E.5-1
  053  ボタンでLEDの明るさを調節する       E.5-2
  057  アナログ入力に応じてLED点滅レートが変化  E.5-3
  057  アナログ入力に応じてLEDの明るさを変える  E.5-4
  059  アナログ入力ピンの値をコンピュータへ送る   E.5-5


第5章の流れは以下のようになっています

        E.5-1 アナログ出力
        E.5-2 デジタル入力、アナログ出力
        E.5-3 アナログ入力、デジタル出力
        E.5-4 アナログ入力、アナログ出力
        E.5-5 シリアル通信 

051 ゆっくり明滅するLED:E.5-1

(1)回路設計

目的: PWM出力でLEDをゆっくり明滅させます
    (アナログ出力)

材料: Mac (Arduino IDE), Arduino UNOボード, LED x1,
    ブレッドボード, ジャンプワイヤ, 抵抗器(1KΩ)
回路: 回路5-1
回路5-1.png

ここの抵抗は220Ω以上を用いることになってますが、『Arduinoをはじめよう 互換キット』では200Ωの次に大きいものが1KΩでした

IMG_4104.jpg

Arduinoをはじめよう 互換キット UNO R3対応互換ボード 初心者専用実験キット 基本部品セット20 in 1 Arduino sidekick basic kit

新品価格
¥3,780から


(2)プログラミング

※スケッチ は、原書版で公開されているスケッチデータを用います
(以下Example 5-5まで同様)

E5_1_Fade
――――――――――(Example 5-1)――――――――――
// Fade an LED in and out, like on a sleeping Apple computer

const int LED = 9; // the pin for the LED
int i = 0; // We'll use this to count up and down

void setup() {
pinMode(LED, OUTPUT); // tell Arduino LED is an output
}

void loop(){

for (i = 0; i < 255; i++) { // loop from 0 to 254 (fade in)
analogWrite(LED, i); // set the LED brightness
delay(10); // Wait 10ms because analogWrite
// is instantaneous and we would
// not see any change
}

for (i = 255; i > 0; i--) { // loop from 255 to 1 (fade out)

analogWrite(LED, i); // set the LED brightness
delay(10); // Wait 10ms
}

}

―――――――――――――――――――――――――――

(3)実行


YouTube https://youtu.be/pfwub5ADuO8

白色LEDがゆっくり明るくなったり暗くなったりします

スケッチに"like on a sleeping Apple computer"とありますが、ちょうどMacBookのスリープインジケータライト (SIL)のような動きをします

053 ボタンでLEDの明るさを調節する:E.5-2

次は、回路5-1にプッシュボタンを追加し、ボタンの押し方でLEDの点灯や明るさを調節します

(1)回路設計

目的: ブッシュボタンの押し方でLEDの点灯・消灯と明るさを制御する
    (デジタル入力、アナログ出力)

材料: Mac (Arduino IDE), Arduino UNOボード, LED x1,
    ブレッドボード, ジャンプワイヤ, 抵抗器(1KΩ),
    抵抗器(10KΩ), プッシュボタン(タクトスイッチ)
回路: 回路5-2
回路5-2.png

(2)プログラミング

@ボタンを押してすぐに離した時はLEDの点灯、消灯を行い、

Aボタンを押し続ける(500 ms以上)とLEDの明るさが変化し、離した時点の明るさで固定するようにします


E5_2_ButtonHold
――――――――――(Example 5-2)――――――――――
// Sketch to change the brightness as you hold the button

const int LED = 9; // the pin for the LED
const int BUTTON = 7; // input pin of the pushbutton

int val = 0; // stores the state of the input pin

int old_val = 0; // stores the previous value of "val"
int state = 0; // 0 = LED off while 1 = LED on

int brightness = 128; // Stores the brightness value
unsigned long startTime = 0; // when did we begin pressing?

void setup() {
pinMode(LED, OUTPUT); // tell Arduino LED is an output
pinMode(BUTTON, INPUT); // and BUTTON is an input
}

void loop() {

val = digitalRead(BUTTON); // read input value and store it
// yum, fresh

// check if there was a transition
if ((val == HIGH) && (old_val == LOW)) {

state = 1 - state; // change the state from off to on
// or vice-versa

startTime = millis(); // millis() is the Arduino clock
// it returns how many milliseconds
// have passed since the board has
// been reset.

// (this line remembers when the button
// was last pressed)
delay(10);
}

// check whether the button is being held down
if ((val == HIGH) && (old_val == HIGH)) {

// If the button is held for more than 500 ms.
if (state == 1 && (millis() - startTime) > 500) {

brightness++; // increment brightness by 1
delay(10); // delay to avoid brightness going
// up too fast

if (brightness > 255) { // 255 is the max brightness

brightness = 0; // if we go over 255
// let's go back to 0
}
}
}

old_val = val; // val is now old, let's store it

if (state == 1) {
analogWrite(LED, brightness); // turn LED ON at the
// current brightness level

} else {
analogWrite(LED, 0); // turn LED OFF
}
}

―――――――――――――――――――――――――――

(3)実行


YouTube https://youtu.be/f2FFqEMreLg

素早くボタンを押すとLEDが点いたり消えたりします

長押しするとLEDがゆっくり明るくなったり暗くなったりし、ボタンから指を離した時の明るさで固定されます

057 アナログ入力に応じてLED点滅レートが変化:E.5-3

ここでは光センサを用いてアナログ入力を行い、その値に応じてLEDの点滅レートを制御します

(1)回路設計

目的: 光センサでLEDの点滅レートを制御する
    (アナログ入力、デジタル出力)

材料: Mac (Arduino IDE), Arduino UNOボード, LED x1,
    ブレッドボード, ジャンプワイヤ, 抵抗器(10KΩ),
    光センサ
回路: 回路5-3
回路5-3.png

(2)プログラミング

E5_3_BlinkRate
――――――――――(Example 5-3)――――――――――
// Blink LED at a rate specified by the value of the analogue input

const int LED = 13; // the pin for the LED

int val = 0; // variable used to store the value
// coming from the sensor
void setup() {
pinMode(LED, OUTPUT); // LED is as an OUTPUT

// Note: Analogue pins are
// automatically set as inputs
}

void loop() {

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

digitalWrite(LED, HIGH); // turn the LED on

delay(val); // stop the program for
// some time

digitalWrite(LED, LOW); // turn the LED off

delay(val); // stop the program for
// some time
}

―――――――――――――――――――――――――――
(3)実行


YouTube https://youtu.be/DZOdyblJW3s

光センサに当たる光の量によって13番ピンLEDの点滅スピードが変化します

(動画は最後にまとめて示します:Example 5-3)
057 アナログ入力に応じてLEDの明るさを変える:E.5-4


続いて、PWM出力(アナログ出力)の9番ピンにLEDを接続し、光センサの値に応じてLEDの明るさを制御します

(1)回路設計

目的: 光センサでLEDの明るさを制御する
    (アナログ入力、アナログ出力)

材料: Mac (Arduino IDE), Arduino UNOボード, LED x1,
    ブレッドボード, ジャンプワイヤ, 抵抗器(10KΩ),
    抵抗器(1KΩ), 光センサ
回路: 回路5-4
回路5-4.png

(2)プログラミング

E5_4_LEDBrightness
――――――――――(Example 5-4)――――――――――
// Set the LED to a brightness specified by the value of the analogue input

const int LED = 9; // the pin for the LED

int val = 0; // variable used to store the value
// coming from the sensor

void setup() {

pinMode(LED, OUTPUT); // LED is as an OUTPUT

// Note: Analogue pins are
// automatically set as inputs
}

void loop() {

val = analogRead(0); // read the value from
// the sensor
analogWrite(LED, val/4); // turn the LED on at
// the brightness set
// by the sensor

delay(10); // stop the program for
// some time
}

―――――――――――――――――――――――――――
(3)実行


YouTube https://youtu.be/SulvEn-6z3A

光センサに当たる光の量によって9番ピンLEDの明るさが変化します

059 アナログ入力ピンの値をコンピュータへ送る:E.5-5


Example 5-4で第5章の目的であるアナログ入出力LEDランプができました

これを応用すれば周りが暗くなるに従って明るくなるモニターやキーボードバックライトを作れるんですかね

最後に光センサを使ってアナログ入力の値を読み取るSerial monitorの使い方(シリアル通信)を学びます

(1)回路設計

回路5-4に同じ

(2)プログラミング

E5_5_Serial
――――――――――(Example 5-5)――――――――――
// Send the computer the values read from analogue input 0

const int SENSOR = 0; // select the input pin for the
// sensor resistor

int val = 0; // variable to store the value coming
// from the sensor

void setup() {

Serial.begin(9600); // open the serial port to send
// data back to the computer at
// 9600 bits per second
}

void loop() {

val = analogRead(SENSOR); // read the value from
// the sensor

Serial.println(val); // print the value to
// the serial port

delay(100); // wait 100ms between
// each send
}

―――――――――――――――――――――――――――
(3)実行


YouTube https://youtu.be/r10XHGNOJ2Y

Arduinoボードにスケッチを書き込み、Arduino IDEでSerial monitorボタンを押すと光センサからの値を表示します

Example 5-1〜5-5の動画まとめ

最後に今回のExample 5-1〜5-5の実験の動画を示します

YouTube  

以上で、『Arduinoをはじめよう 第3版』第5章のお勉強を終えます

ではまた〜


【永久保証付き】Arduino Uno

新品価格
¥3,240から


Raspberry Pi3 Model B ボード&ケースセット (Element14版, Clear)-Physical Computing Lab

新品価格
¥5,780から


Arduinoをはじめよう 第3版 (Make:PROJECTS)

新品価格
¥2,160から


Arduinoをはじめよう 互換キット UNO R3対応互換ボード 初心者専用実験キット 基本部品セット20 in 1 Arduino sidekick basic kit

新品価格
¥3,780から


Arduinoをはじめようキット

新品価格
¥4,310から


Arduino エントリーキット(Uno版)- Physical Computing Lab

新品価格
¥4,320から


タミヤ 楽しい工作シリーズ No.216 3ch RCロボット製作セット 70216

新品価格
¥6,327から


エレキット 水圧式ロボットアーム MR-9105

新品価格
¥4,560から


エレキット バトルタイタン2 MR-9101R

新品価格
¥3,163から


世界最小★OZO-010102-0102 World's Smallest SMART Robot - Dual Pack, 1 Crystal White & 1 Titanium Black 2 Bonus Limited-Edition Skins スマートロボット Ozobot社【並行輸入】

新品価格
¥6,000から


タミヤ 楽しい工作シリーズ No.211 アームクローラー工作セット 70211

新品価格
¥1,345から


タミヤ 楽しい工作シリーズ No.97 ツインモーターギヤーボックス (70097)

新品価格
¥587から


タミヤ 楽しい工作シリーズ No.106 4チャンネル・リモコンボックス (70106)

新品価格
¥1,118から


posted by riserobo: at 17:52| Comment(0) | TrackBack(0) | Arduino

2016年09月20日

A5:4 スケッチ入門:デジタル入出力 LEDランプ作成A


前回の続きです

  ページ  実行内容                スケッチ
  038   ボタンが押されている間、LEDを点ける  E.4-2
  040   ボタンを1回押すと点灯を続けるLED   E.4-3
  042   ボタンを押した時の挙動を改善      E.4-4
  043   バウンシングに対応した最終版      E.4-5

038 ボタンが押されている間、LEDを点ける:E.4-2

Example 4-1ではLEDが1秒ごとに点滅しましたが、

Example 4-2ではボタンを押している間だけLEDが点きます

(1)回路設計

目的: プッシュボタン(センサー)によりLEDの点灯を制御する

材料: Mac (Arduino IDE), Arduino UNOボード, LED x1,
    ブレッドボード, ジャンプワイヤ, 抵抗器(10KΩ),
    プッシュボタン(タクトスイッチ)
    
回路: 回路4-2

回路4-2.png

回路4-1にブッシュボタン制御用ブレッドボードを7番ピンに接続します

この回路に必要な部品は全て『Arduinoをはじめよう 互換キット UNO R3対応互換ボード』に入っていました

IMG_4104.jpg

Arduinoをはじめよう 互換キット UNO R3対応互換ボード 初心者専用実験キット 基本部品セット20 in 1 Arduino sidekick basic kit

新品価格
¥3,780から


(2)プログラミング

スケッチ:Example 4-2

上記スケッチ E.4-1同様、原書版で公開されているスケッチデータを用います(以下Example 4-5まで同様)

E4_2_LED_Button
――――――――――(Example 4-2)――――――――――
// Turn on LED while the button is pressed

const int LED = 13; // the pin for the LED
const int BUTTON = 7; // the input pin where the
// pushbutton is connected
int val = 0; // val will be used to store the state
// of the input pin

void setup() {
pinMode(LED, OUTPUT); // tell Arduino LED is an output
pinMode(BUTTON, INPUT); // and BUTTON is an input
}

void loop(){
val = digitalRead(BUTTON); // read input value and store it

// check whether the input is HIGH (button pressed)
if (val == HIGH) {
digitalWrite(LED, HIGH); // turn LED ON
} else {
digitalWrite(LED, LOW);
}
}

―――――――――――――――――――――――――――

(3)実行

実際に動かすと、ボタンを押している間だけLEDが点きます


YouTube https://youtu.be/dZq70-5B6Jw

40 ボタンを1回押すと点灯を続けるLED:E.4-3

Example 4-2のようにLEDを点灯させるためにボタンを押し続けなくてはいけないのは大変ですので、Example 4-3ではボタンを1回押すとLEDが点灯し、もう一度押すと消灯するようにしたい

(1)回路設計

Example 4-2に同じ

(2)プログラミング

スケッチ:Example 4-3

E4_3_LED_KeepOn
――――――――――(Example 4-3)――――――――――
// Turn on LED when the button is pressed and keep it on after it is released

const int LED = 13; // the pin for the LED
const int BUTTON = 7; // the input pin where the
// pushbutton is connected
int val = 0; // val will be used to store the state
// of the input pin
int state = 0; // 0 = LED off while 1 = LED on

void setup() {
pinMode(LED, OUTPUT); // tell Arduino LED is an output
pinMode(BUTTON, INPUT); // and BUTTON is an input
}

void loop() {
val = digitalRead(BUTTON); // read input value and store it

// check if the input is HIGH (button pressed)
// and change the state
if (val == HIGH) {
state = 1 - state;
}

if (state == 1) {
digitalWrite(LED, HIGH); // turn LED ON
} else {
digitalWrite(LED, LOW);
}
}

―――――――――――――――――――――――――――
Example 4-2からの変更点を赤字で示しています

(3)実行

ボタンを押すとLEDが点きます・・・が、押した時に点くか消えるかは気分次第というか・・・ランダムなような・・・押している時間依存的なような不安定な挙動をします


YouTube https://youtu.be/CeVU-okcHMA

これは state = 1 - state; によって

LEDの状態(state)が1(点灯)なら state = 1 - state(=1)=0(消灯)

LEDの状態(state)が0(消灯)なら state = 1 - state(=0)=1(点灯)

としてLEDの状態を変えますが、ボタンを押しているほんのすこしの間にこの状態変化の読み取りが次々と変化し偶然の結果としてどちらかの状態になりLEDが光ったり消えたりすることになります

LEDの点灯を偶然に任せるというのも面白いのですが、ここでは実用的になるように改良してます
042 ボタンを押した時の挙動を改善:E.4-4

Example 4-4ではExample 4-3の不具合をスケッチの改善する

(1)回路設計

Example 4-2に同じ

(2)プログラミング

スケッチ:Example 4-4

E4_4_NewImprovedButton
――――――――――(Example 4-4)――――――――――
// New and improved button press formula!

const int LED = 13; // the pin for the LED
const int BUTTON = 7; // the input pin where the
// pushbutton is connected
int val = 0; // val will be used to store the state
// of the input pin
int old_val = 0; // this variable stores the previous
// value of "val"
int state = 0; // 0 = LED off and 1 = LED on

void setup() {
pinMode(LED, OUTPUT); // tell Arduino LED is an output
pinMode(BUTTON, INPUT); // and BUTTON is an input
}
void loop(){
val = digitalRead(BUTTON); // read input value and store it
// yum, fresh

// check if there was a transition
if ((val == HIGH) && (old_val == LOW)){
state = 1 - state;
}

old_val = val; // val is now old, let's store it

if (state == 1) {
digitalWrite(LED, HIGH); // turn LED ON
} else {
digitalWrite(LED, LOW);
}
}

―――――――――――――――――――――――――――
Example 4-3からの変更点を赤字で示しています

ここでは押す前のボタンの状態をint old_val = 0; で保存して

((val == HIGH) && (old_val == LOW))で押した時のボタンの状態(val)がHIGHでかつ(&&)押す前のボタンの状態(old_val)がLOWの時 state = 1 - stateとすることでボタンを押している間にstateが変化しないようにしています

・・・ボタンでLEDを点けたり消したりするだけでこんなに面倒くさいことになるとは・・・σ(^_^;)

(3)実行

早速実行してみるとExample 4-3の時と違いがわかりませんσ(^_^;)



YouTube https://youtu.be/PX0DuWLJ8ZE

これはプッシュボタンの機械的な接触の問題でバウンスという現象の影響だそうで、delayを10〜50 msほど入れれば解消されるそうです
043 バウンシングに対応した最終版:E.4-5

Example 4-5でExample 4-4のバウンスの問題を解消する

(1)回路設計

Example 4-2に同じ

(2)プログラミング

スケッチ:Example 4-5

E4_5_DebounceWithButton
――――――――――(Example 4-5)――――――――――
// Another new and improved formula for button presses--with simple debouncing!

const int LED = 13; // the pin for the LED
const int BUTTON = 7; // the input pin where the
// pushbutton is connected
int val = 0; // val will be used to store the state
// of the input pin
int old_val = 0; // this variable stores the previous
// value of "val"
int state = 0; // 0 = LED off and 1 = LED on

void setup() {
pinMode(LED, OUTPUT); // tell Arduino LED is an output
pinMode(BUTTON, INPUT); // and BUTTON is an input
}

void loop(){
val = digitalRead(BUTTON); // read input value and store it
// yum, fresh

// check if there was a transition
if ((val == HIGH) && (old_val == LOW)){
state = 1 - state;
delay(10);
}

old_val = val; // val is now old, let's store it

if (state == 1) {
digitalWrite(LED, HIGH); // turn LED ON
} else {
digitalWrite(LED, LOW);
}
}

―――――――――――――――――――――――――――
Example 4-4からの変更点を赤字で示しています

ここでは state = 1 - state;の後に delay(10);を入れているだけです

(3)実行


YouTube https://youtu.be/Of-LSemRt64

ん? 確かにマシになっているように思いますが、まだちょっと不安定なような?

これはプッシュスイッチの問題かもしれないので、とりあえずこれで
Example 4-2からExample 4-5の結果

ここまで(Example 4-2からExample 4-5)のところを動画でまとめて示します

あまり代わり映えのしない映像なんでアレですが・・・


YouTube  https://youtu.be/bCn_khchi6g

『Arduinoをはじめよう 第3版』購入のすすめ

『Arduinoをはじめよう 第3版』の眼目はArduinoを用いる上での思想や開発の手順だったりします

このブログの内容はそこまで書かないので是非『Arduinoをはじめよう 第3版』を手にとってみてください

一通り読みましたがArduinoを基礎から学習する上でよくできた教科書と思います

ではでは


【永久保証付き】Arduino Uno

新品価格
¥3,240から


Raspberry Pi3 Model B ボード&ケースセット (Element14版, Clear)-Physical Computing Lab

新品価格
¥5,780から


Arduinoをはじめよう 第3版 (Make:PROJECTS)

新品価格
¥2,160から


Arduinoをはじめよう 互換キット UNO R3対応互換ボード 初心者専用実験キット 基本部品セット20 in 1 Arduino sidekick basic kit

新品価格
¥3,780から


Arduinoをはじめようキット

新品価格
¥4,310から


Arduino エントリーキット(Uno版)- Physical Computing Lab

新品価格
¥4,320から


タミヤ 楽しい工作シリーズ No.216 3ch RCロボット製作セット 70216

新品価格
¥6,327から


エレキット 水圧式ロボットアーム MR-9105

新品価格
¥4,560から


エレキット バトルタイタン2 MR-9101R

新品価格
¥3,163から


世界最小★OZO-010102-0102 World's Smallest SMART Robot - Dual Pack, 1 Crystal White & 1 Titanium Black 2 Bonus Limited-Edition Skins スマートロボット Ozobot社【並行輸入】

新品価格
¥6,000から


タミヤ 楽しい工作シリーズ No.211 アームクローラー工作セット 70211

新品価格
¥1,345から


タミヤ 楽しい工作シリーズ No.97 ツインモーターギヤーボックス (70097)

新品価格
¥587から


タミヤ 楽しい工作シリーズ No.106 4チャンネル・リモコンボックス (70106)

新品価格
¥1,118から


posted by riserobo: at 18:31| Comment(0) | TrackBack(0) | Arduino
検索
QRコード
RSS取得
プロフィール
riserobo:さんの画像
riserobo:
×

この広告は30日以上新しい記事の更新がないブログに表示されております。