tag:blogger.com,1999:blog-66970505534531322382024-09-12T22:56:42.215+09:00Arduino@東北芸工大東北芸術工科大学プロダクトデザイン学科の授業用です。久世http://www.blogger.com/profile/06898487025751982552[email protected]Blogger31125tag:blogger.com,1999:blog-6697050553453132238.post-42440898567609078372009-07-21T16:07:00.000+09:002009-07-21T16:09:39.077+09:00ひらおかさんのプログラムサンプル3<pre> <br /><span style="color: #777755;">//For Hiraoka</span><br /><span style="color: #777755;">//ShockSensor & Solenoid & Motor</span><br /><span style="color: #777755;">//2009.7.21</span><br /><br /><span style="color: #777755;">//PinAssign</span><br /><span style="color: #996600;">int</span> SOLENOID=11;<br /><span style="color: #996600;">int</span> SWITCH=12;<br /><span style="color: #996600;">int</span> SHOCK=14;<br /><span style="color: #777755;">//StepMotorPin</span><br /><span style="color: #996600;">int</span> ST_X1=2;<br /><span style="color: #996600;">int</span> ST_X2=4;<br /><span style="color: #996600;">int</span> ST_Y1=3;<br /><span style="color: #996600;">int</span> ST_Y2=5;<br /><span style="color: #777755;">//Tsumami</span><br /><span style="color: #996600;">int</span> Pot=5;<br /><br /><span style="color: #777755;">//Value</span><br />#define MAX 100<br /><span style="color: #996600;">int</span> rythm_cnt=0;<br /><span style="color: #996600;">int</span> rythm[MAX];<br /><span style="color: #996600;">int</span> dly;<br /><span style="color: #996600;">int</span> MotorCnt;<br /><br /><span style="color: #777755;">//Setup</span><br /><span style="color: #CC6600;">void</span> <span style="color: #993300;"><b>setup</b></span>(){<br /> <span style="color: #996600;">pinMode</span>(SOLENOID,<span style="color: #CC0000;">OUTPUT</span>);<br /> <span style="color: #996600;">pinMode</span>(SHOCK,<span style="color: #CC0000;">INPUT</span>);<br /> <span style="color: #996600;">pinMode</span>(SWITCH,<span style="color: #CC0000;">INPUT</span>);<br /> <span style="color: #996600;">pinMode</span>(ST_X1, <span style="color: #CC0000;">OUTPUT</span>);<br /> <span style="color: #996600;">pinMode</span>(ST_X2, <span style="color: #CC0000;">OUTPUT</span>);<br /> <span style="color: #996600;">pinMode</span>(ST_Y1, <span style="color: #CC0000;">OUTPUT</span>);<br /> <span style="color: #996600;">pinMode</span>(ST_Y2, <span style="color: #CC0000;">OUTPUT</span>);<br /> <span style="color: #996600;">pinMode</span>(ledPin, <span style="color: #CC0000;">OUTPUT</span>);<br /><br /> <span style="color: #CC6600;">for</span>(<span style="color: #996600;">int</span> i=0; i<MAX; i++){<br /> rythm[i]=0;<br /> }<br />}<br /><br /><span style="color: #777755;">//Loop</span><br /><span style="color: #CC6600;">void</span> <span style="color: #993300;"><b>loop</b></span>(){<br /> rythm_cnt++;<br /> <span style="color: #CC6600;">if</span>(rythm_cnt>=MAX) rythm_cnt=0;<br /> <span style="color: #CC6600;">if</span>(<span style="color: #996600;">digitalRead</span>(SHOCK)==1){<br /> rythm[rythm_cnt]=1;<br /> }<br /><br /> dly=50;<br /> <span style="color: #CC6600;">for</span>(<span style="color: #996600;">int</span> i=0; i<dly; i++){<br /> <span style="color: #996600;">delay</span>(1);<br /> <span style="color: #CC6600;">if</span>(<span style="color: #996600;">digitalRead</span>(SWITCH)==1) {<br /> <span style="color: #CC6600;">for</span>(<span style="color: #996600;">int</span> j=0; j<MAX; j++){<br /> rythm[j]=0;<br /> rythm_cnt=0;<br /> }<br /> }<br /> <span style="color: #CC6600;">if</span>(rythm[rythm_cnt]==0){<br /> MotorCnt++;<br /> MoveMotor(MotorCnt);<br /> }<br /> }<br /><br /> <span style="color: #CC6600;">if</span>(rythm[rythm_cnt]==1){<br /> <span style="color: #996600;">digitalWrite</span>(SOLENOID,<span style="color: #CC0000;">HIGH</span>);<br /> }<br /> <span style="color: #CC6600;">else</span>{<br /> <span style="color: #996600;">digitalWrite</span>(SOLENOID,<span style="color: #CC0000;">LOW</span>);<br /> MotorCnt++;<br /> MoveMotor(MotorCnt);<br /><br /> }<br />}<br /><br /><br /><span style="color: #777755;">//MoveMotor</span><br /><span style="color: #CC6600;">void</span> MoveMotor(<span style="color: #996600;">int</span> stp){<br /> <span style="color: #996600;">int</span> s;<br /> s=stp%8;<br /><br /> <span style="color: #CC6600;">switch</span>(s){<br /> <span style="color: #CC6600;">case</span> 0:<br /> <span style="color: #996600;">digitalWrite</span>(ST_X1, <span style="color: #CC0000;">HIGH</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_X2, <span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_Y1, <span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_Y2, <span style="color: #CC0000;">LOW</span>);<br /> dly = <span style="color: #996600;">analogRead</span>(Pot)/4;<br /> <span style="color: #996600;">delay</span>(dly);<br /> break;<br /><br /> <span style="color: #CC6600;">case</span> 1:<br /> <span style="color: #996600;">digitalWrite</span>(ST_X1, <span style="color: #CC0000;">HIGH</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_X2, <span style="color: #CC0000;">HIGH</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_Y1, <span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_Y2, <span style="color: #CC0000;">LOW</span>);<br /> dly = <span style="color: #996600;">analogRead</span>(Pot)/4;<br /> <span style="color: #996600;">delay</span>(dly);<br /> break;<br /><br /> <span style="color: #CC6600;">case</span> 2:<br /> <span style="color: #996600;">digitalWrite</span>(ST_X1, <span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_X2, <span style="color: #CC0000;">HIGH</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_Y1, <span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_Y2, <span style="color: #CC0000;">LOW</span>);<br /> dly = <span style="color: #996600;">analogRead</span>(Pot)/4;<br /> <span style="color: #996600;">delay</span>(dly);<br /> break;<br /><br /> <span style="color: #CC6600;">case</span> 3:<br /> <span style="color: #996600;">digitalWrite</span>(ST_X1, <span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_X2, <span style="color: #CC0000;">HIGH</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_Y1, <span style="color: #CC0000;">HIGH</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_Y2, <span style="color: #CC0000;">LOW</span>);<br /> dly = <span style="color: #996600;">analogRead</span>(Pot)/4;<br /> <span style="color: #996600;">delay</span>(dly);<br /> break;<br /><br /> <span style="color: #CC6600;">case</span> 4:<br /> <span style="color: #996600;">digitalWrite</span>(ST_X1, <span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_X2, <span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_Y1, <span style="color: #CC0000;">HIGH</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_Y2, <span style="color: #CC0000;">LOW</span>);<br /> dly = <span style="color: #996600;">analogRead</span>(Pot)/4;<br /> <span style="color: #996600;">delay</span>(dly);<br /> break;<br /><br /> <span style="color: #CC6600;">case</span> 5:<br /> <span style="color: #996600;">digitalWrite</span>(ST_X1, <span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_X2, <span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_Y1, <span style="color: #CC0000;">HIGH</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_Y2, <span style="color: #CC0000;">HIGH</span>);<br /> dly = <span style="color: #996600;">analogRead</span>(Pot)/4;<br /> <span style="color: #996600;">delay</span>(dly);<br /> break;<br /><br /> <span style="color: #CC6600;">case</span> 6:<br /> <span style="color: #996600;">digitalWrite</span>(ST_X1, <span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_X2, <span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_Y1, <span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_Y2, <span style="color: #CC0000;">HIGH</span>);<br /> dly = <span style="color: #996600;">analogRead</span>(Pot)/4;<br /> <span style="color: #996600;">delay</span>(dly);<br /> break;<br /><br /> <span style="color: #CC6600;">case</span> 7:<br /> <span style="color: #996600;">digitalWrite</span>(ST_X1, <span style="color: #CC0000;">HIGH</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_X2, <span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_Y1, <span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_Y2, <span style="color: #CC0000;">HIGH</span>);<br /> dly = <span style="color: #996600;">analogRead</span>(Pot)/4;<br /> <span style="color: #996600;">delay</span>(dly);<br /> break;<br /> }<br />}<br /><br /><span style="color: #777755;">//StopMotor</span><br /><span style="color: #CC6600;">void</span> StopMotor(){<br /> <span style="color: #996600;">digitalWrite</span>(ST_X1, <span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_X2, <span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_Y1, <span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_Y2, <span style="color: #CC0000;">LOW</span>);<br />}<br /><br /><br /></pre>久世http://www.blogger.com/profile/06898487025751982552[email protected]0tag:blogger.com,1999:blog-6697050553453132238.post-87999340386577439202009-07-17T08:52:00.001+09:002009-07-17T08:53:14.848+09:00サーボモーターが4つ、スイッチが4つ、リセットスイッチが1つ。<pre> <br /><span style="color: #777755;">//For Monma</span><br /><span style="color: #777755;">//Servo*4 and Switch*4 and ResetSwitch*1</span><br /><span style="color: #777755;">//2009.7.17</span><br /><br /><span style="color: #777755;">//Pin</span><br /><span style="color: #777755;">//DIGITAL PIN (8,9,10,11)</span><br /><span style="color: #996600;">int</span> Servo_pin[4]={8,9,10,11};<br /><br /><span style="color: #777755;">//ANALOG IN PIN (0, 1, 2, 3)</span><br /><span style="color: #996600;">int</span> Switch_pin[4]={14,15,16,17};<br /><span style="color: #777755;">//ANALOG IN PIN (5)</span><br /><span style="color: #996600;">int</span> ResetSwitch_pin = 19;<br /><br /><span style="color: #777755;">//ServoSpeed</span><br /><span style="color: #996600;">int</span> Speed_val[4]={50,50,50,50};<br /><br /><br /><br /><span style="color: #777755;">//Value</span><br /><span style="color: #CC6600;">signed</span> <span style="color: #996600;">int</span> Servo_val[4]={<br /> 0,0,0,0};<br /><span style="color: #996600;">int</span> MaxCnt=2000;<br /><br /><span style="color: #777755;">//Init</span><br /><span style="color: #CC6600;">void</span> <span style="color: #993300;"><b>setup</b></span>(){<br /> <span style="color: #CC6600;">for</span>(<span style="color: #996600;">int</span> i=0; i<4; i++){<br /> <span style="color: #996600;">pinMode</span>(Servo_pin[i],<span style="color: #CC0000;">OUTPUT</span>);<br /> <span style="color: #996600;">pinMode</span>(Switch_pin[i],<span style="color: #CC0000;">INPUT</span>);<br /> Servo_val[i]=90;<br /> }<br /> <span style="color: #996600;">pinMode</span>(ResetSwitch_pin,<span style="color: #CC0000;">INPUT</span>);<br />}<br /><br /><span style="color: #777755;">//Loop</span><br /><span style="color: #CC6600;">void</span> <span style="color: #993300;"><b>loop</b></span>(){<br /> <span style="color: #CC6600;">for</span>(<span style="color: #996600;">int</span> i=0; i<1; i++){<br /> <span style="color: #CC6600;">if</span>(<span style="color: #996600;">digitalRead</span>(Switch_pin[i])){<br /> Servo_val[i]+=Speed_val[i];<br /> <span style="color: #CC6600;">if</span>(Servo_val[i]>MaxCnt)Servo_val[i]=MaxCnt;<br /> } <br /> <span style="color: #CC6600;">else</span>{<br /> <span style="color: #CC6600;">if</span>(<span style="color: #996600;">digitalRead</span>(ResetSwitch_pin)==1) Servo_val[i]=90;<br /> }<br /> }<br /> Control_Servo4();<br />}<br /><br /><br /><span style="color: #CC6600;">void</span> Control_Servo4(){<br /> <span style="color: #777755;">//Control Servo 4</span><br /> <span style="color: #CC6600;">for</span>(<span style="color: #996600;">int</span> i=0; i<4; i++){<br /> <span style="color: #996600;">digitalWrite</span>(Servo_pin[i],<span style="color: #CC0000;">HIGH</span>);<br /> }<br /> <span style="color: #CC6600;">for</span>(<span style="color: #996600;">int</span> i=0; i<4; i++){<br /> <span style="color: #996600;">delayMicroseconds</span>(Servo_val[i]+500/4);<br /> }<br /> <span style="color: #CC6600;">for</span>(<span style="color: #996600;">int</span> i=0; i<4; i++){<br /> <span style="color: #996600;">digitalWrite</span>(Servo_pin[i],<span style="color: #CC0000;">LOW</span>);<br /> }<br /> <span style="color: #CC6600;">for</span>(<span style="color: #996600;">int</span> i=0; i<4; i++){<br /> <span style="color: #996600;">delayMicroseconds</span>((10000-(Servo_val[i]+500))/4);<br /> }<br /> <span style="color: #996600;">delayMicroseconds</span>(10000);<br />}<br /><br /></pre>久世http://www.blogger.com/profile/06898487025751982552[email protected]1tag:blogger.com,1999:blog-6697050553453132238.post-34622185902832496752009-07-14T16:46:00.005+09:002009-07-14T16:50:45.224+09:00タミヤのパーツ<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpNaJfkTdf3wqUIiBGzZ_sF54ol-n5EBfSAJOBSYukBN-13XBvBIjPTT8dush3R154Fx1UsQVpd07jAo1QDvcNBWTOYWcWT0IXw9NEtpAMCD5QAuu8ysNFkLmGx5WYzLI3lsJEvCl49bNJ/s1600-h/%E3%83%94%E3%82%AF%E3%83%81%E3%83%A3+2.png"><img style="cursor:pointer; cursor:hand;width: 320px; height: 224px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpNaJfkTdf3wqUIiBGzZ_sF54ol-n5EBfSAJOBSYukBN-13XBvBIjPTT8dush3R154Fx1UsQVpd07jAo1QDvcNBWTOYWcWT0IXw9NEtpAMCD5QAuu8ysNFkLmGx5WYzLI3lsJEvCl49bNJ/s320/%E3%83%94%E3%82%AF%E3%83%81%E3%83%A3+2.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5358219194590054898" /></a><br />ユニバーサルギアボックス<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihyphenhyphenrGvMG5-KZuqLVLQIFOFYnTamuddTQMx81uLtLrtx1oZcyxiag5l-HstxRWXFUzvqVPZETKJIxfKmi3HKspY3_WFZpdBWDSuFKnibf0F99V9SpS07pc1y5GN5CyMsXGJy8szbJHBpSvM/s1600-h/%E3%83%94%E3%82%AF%E3%83%81%E3%83%A3+3.png"><img style="cursor:pointer; cursor:hand;width: 320px; height: 190px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihyphenhyphenrGvMG5-KZuqLVLQIFOFYnTamuddTQMx81uLtLrtx1oZcyxiag5l-HstxRWXFUzvqVPZETKJIxfKmi3HKspY3_WFZpdBWDSuFKnibf0F99V9SpS07pc1y5GN5CyMsXGJy8szbJHBpSvM/s320/%E3%83%94%E3%82%AF%E3%83%81%E3%83%A3+3.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5358219489484067522" /></a><br />工作ロボ&クラフト<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjIe8Rd5mW2XYeYi9Pa7ZTCEXIVmJvU6aP4CZ2wsy79zHg3wZnlEAfxlc-QhMv1c0pow-zEEuXLy8V9iZNr22fSZRuBF0Ig3IoMGTzzN3DZMFLYgRQBK8QtW5xtj-MuIq7wbHtRHQwgEiO7/s1600-h/%E3%83%94%E3%82%AF%E3%83%81%E3%83%A3+4.png"><img style="cursor:pointer; cursor:hand;width: 320px; height: 214px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjIe8Rd5mW2XYeYi9Pa7ZTCEXIVmJvU6aP4CZ2wsy79zHg3wZnlEAfxlc-QhMv1c0pow-zEEuXLy8V9iZNr22fSZRuBF0Ig3IoMGTzzN3DZMFLYgRQBK8QtW5xtj-MuIq7wbHtRHQwgEiO7/s320/%E3%83%94%E3%82%AF%E3%83%81%E3%83%A3+4.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5358220050528647490" /></a><br />山形駅前のシバタモデルにありました。「楽しい工作シリーズ」久世http://www.blogger.com/profile/06898487025751982552[email protected]0tag:blogger.com,1999:blog-6697050553453132238.post-19120399254942214802009-07-08T16:09:00.003+09:002009-07-08T16:15:51.332+09:00アルミの板の素材<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi21doot-5k773symUiyn5HU8iCXVdo-_jjFvnCzBxyoHCYijWZwHdvqf0MD7cI_W05LTypXzBjS0-PrZfzGVRrsNCHUPQrcuReXTOOZdKsbm60zC8sUbHzmdS-_5wHgRWtoYGI-QweXvwH/s1600-h/%E3%83%94%E3%82%AF%E3%83%81%E3%83%A3+12.png"><img style="cursor:pointer; cursor:hand;width: 320px; height: 232px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi21doot-5k773symUiyn5HU8iCXVdo-_jjFvnCzBxyoHCYijWZwHdvqf0MD7cI_W05LTypXzBjS0-PrZfzGVRrsNCHUPQrcuReXTOOZdKsbm60zC8sUbHzmdS-_5wHgRWtoYGI-QweXvwH/s320/%E3%83%94%E3%82%AF%E3%83%81%E3%83%A3+12.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5355983632378289170" /></a><br /><br />アルミの板は、NCマシン(いつもブーンという機械)で削れます。<br />アクリルのように、板をカットして、折り曲げることでいろんな形にできます。<br /><br />削りやすくできているアルミが、「A5052」です。「快削アルミ」ともいいます。<br />ホームセンターで売っているアルミの板だと、粘りっこいアルミになっていて、削りにくいです。ロボット系を考えている人は、アルミはA5052にしないと加工がやりにくいです。<br /><a href="http://www.originalmind.co.jp/i/0126000528.html">オリジナルマインドで買えます</a>。久世http://www.blogger.com/profile/06898487025751982552[email protected]0tag:blogger.com,1999:blog-6697050553453132238.post-59461331499226761402009-07-08T15:58:00.002+09:002009-07-08T16:08:55.768+09:00ベアリングなどの動かす系の部品<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4DQklMkbGCZTdTqj1dezc8g1z_r92ye6aUHJdIu8aE7QwjfW3-VKZgBuH_eecYAsHsuBxh_rNzzV0hcb1DUCe1GX_phHnWQNOnTVwJgrkH52tv2j3MThgYXU64OyS0NhgBQIjWSJ9AOSD/s1600-h/%E3%83%94%E3%82%AF%E3%83%81%E3%83%A3+9.png"><img style="cursor:pointer; cursor:hand;width: 320px; height: 222px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4DQklMkbGCZTdTqj1dezc8g1z_r92ye6aUHJdIu8aE7QwjfW3-VKZgBuH_eecYAsHsuBxh_rNzzV0hcb1DUCe1GX_phHnWQNOnTVwJgrkH52tv2j3MThgYXU64OyS0NhgBQIjWSJ9AOSD/s320/%E3%83%94%E3%82%AF%E3%83%81%E3%83%A3+9.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5355980487955765842" /></a><br /><br /><a href="http://www.originalmind.co.jp/">オリジナルマインド</a><br /><br />回転するものを作りたいときに、きちんとベアリングを入れてあるかどうかが、キーポイントになります。外から見えなくて地味だけど、しっかり作りたい人はいれておいて間違いないです。<br /><br /><a href="http://www.originalmind.co.jp/cargo5/bearingholder/">ベアリングで、板に軸を固定する方法が紹介されていて、固定方法を考えるのに参考になります</a>。久世http://www.blogger.com/profile/06898487025751982552[email protected]0tag:blogger.com,1999:blog-6697050553453132238.post-40691247773966172962009-07-08T14:58:00.002+09:002009-07-08T15:55:42.295+09:00Arduino関係の購入先<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh0U1mA8tRiEO38JIlj4MYIWZ7HOQD1Bb__LX7nXV6AR83J3rLWpiKTAYyh9gXnPLZsjdYKx8X2pSxT5vmdxVGVnQPBtl8zSnWgJKoAT7b0cpNeFKXJ24AcicfhtXjwqqhNxJlpwma5Z4Np/s1600-h/%E3%83%94%E3%82%AF%E3%83%81%E3%83%A3+11.png"><img style="cursor:pointer; cursor:hand;width: 320px; height: 233px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh0U1mA8tRiEO38JIlj4MYIWZ7HOQD1Bb__LX7nXV6AR83J3rLWpiKTAYyh9gXnPLZsjdYKx8X2pSxT5vmdxVGVnQPBtl8zSnWgJKoAT7b0cpNeFKXJ24AcicfhtXjwqqhNxJlpwma5Z4Np/s320/%E3%83%94%E3%82%AF%E3%83%81%E3%83%A3+11.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5355979313083127842" /></a><br /><a href="http://www.switch-science.com/">スイッチサイエンス</a><br /><br />Arduinoをはじめ、使いやすくできているいろんな部品の大元は、Sparkfunという海外のお店です。もともと学生が始めた電子回路の情報サイトがお店になりました。<a href="http://jp.makezine.com/blog/2008/03/make_sparkfun_electronics.html">詳細はこちら</a>久世http://www.blogger.com/profile/06898487025751982552[email protected]0tag:blogger.com,1999:blog-6697050553453132238.post-20013124323989983772009-07-07T19:45:00.009+09:002009-07-08T08:31:13.713+09:00LEDいろいろ<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhptwXM5cYZgwmBOCgfXp8kM9t-TNTsnNUk_96TCZw4qF69jn8f8O0l3WWhMIs2psb1mWbTcO2b0OHFnJp_VSEG8V-yV7-9zjZqLLpnRDQapwnPEVrgL5uIDqf9jQFeHZzVIWsGALKUmYX/s1600-h/LED%EF%BC%91.png"><img style="cursor:pointer; cursor:hand;width: 320px; height: 218px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhptwXM5cYZgwmBOCgfXp8kM9t-TNTsnNUk_96TCZw4qF69jn8f8O0l3WWhMIs2psb1mWbTcO2b0OHFnJp_VSEG8V-yV7-9zjZqLLpnRDQapwnPEVrgL5uIDqf9jQFeHZzVIWsGALKUmYX/s320/LED%EF%BC%91.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5355671232073913026" /></a><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhCxQn9JL-ML1OvprzhLK4HEjPmBtSCgnesWNaVuUA0fYSk4zqCI8z_mp6xNXuUq9kcEEZFFLgmv7UHxBNYZMnzDULtZA3LWOj8WBZ8xKHZtPfa5AMwj17bSL7z47TPiojwOQXWmZf62VJV/s1600-h/%E3%83%94%E3%82%AF%E3%83%81%E3%83%A3+13.png"><img style="cursor:pointer; cursor:hand;width: 320px; height: 211px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhCxQn9JL-ML1OvprzhLK4HEjPmBtSCgnesWNaVuUA0fYSk4zqCI8z_mp6xNXuUq9kcEEZFFLgmv7UHxBNYZMnzDULtZA3LWOj8WBZ8xKHZtPfa5AMwj17bSL7z47TPiojwOQXWmZf62VJV/s320/%E3%83%94%E3%82%AF%E3%83%81%E3%83%A3+13.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5355669415016366418" /></a><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2jKBh6pzPPnMtNMumQ7BwG0zCXB-5v-Er17waQuyK0XuIaNv1u8JLDM8k8noIHgWepl7KeJOnSUjT6FJuN9pvOR6twnG1xU9E0IBBxAFDDzDlYlv7_eXaUOwX-XwwThvHpCp4mqBuDgbW/s1600-h/%E3%83%94%E3%82%AF%E3%83%81%E3%83%A3+12.png"><img style="cursor:pointer; cursor:hand;width: 320px; height: 213px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2jKBh6pzPPnMtNMumQ7BwG0zCXB-5v-Er17waQuyK0XuIaNv1u8JLDM8k8noIHgWepl7KeJOnSUjT6FJuN9pvOR6twnG1xU9E0IBBxAFDDzDlYlv7_eXaUOwX-XwwThvHpCp4mqBuDgbW/s320/%E3%83%94%E3%82%AF%E3%83%81%E3%83%A3+12.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5355669247323758706" /></a><br />LEDは、秋月電子で買うのが安いです。大量に欲しいときも、だいたい大丈夫です。<br />最近、<a href="http://akizukidenshi.com/catalog/c/ctapeled">テープ状のLED</a>を扱ってくれてるので、LEDで手軽に広めに明るくしたいところなどは便利です。<br /><br />最近は、千石電商がLED向けに、放熱基板を売ってくれてます。手軽にLED照明を作りたい人は千石電商の基板がいいと思います。通販では扱ってないのかな??<br /><br />その他で、ものすごく明るいLEDが欲しかったりすると、「パワーLED」って呼ばれるものがあります。<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJ_cUIymvz9rqGIaJgKY6CumalT8nq8yia8MFEpxbAJok-UY9OXa3nZURtsHO3mVBOMHG6mCGA2DaMMYnFNA8ZNEy5QO_lv67p3r6mnCCBK5V5tkRzHNCrfm6xm6ILmYwOdoOO6XRGn6te/s1600-h/%E3%83%94%E3%82%AF%E3%83%81%E3%83%A3+17.png"><img style="cursor:pointer; cursor:hand;width: 320px; height: 211px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJ_cUIymvz9rqGIaJgKY6CumalT8nq8yia8MFEpxbAJok-UY9OXa3nZURtsHO3mVBOMHG6mCGA2DaMMYnFNA8ZNEy5QO_lv67p3r6mnCCBK5V5tkRzHNCrfm6xm6ILmYwOdoOO6XRGn6te/s320/%E3%83%94%E3%82%AF%E3%83%81%E3%83%A3+17.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5355864492444575362" /></a><br />これは、<a href="http://strawberry-linux.com/catalog/items?code=14008">ストロベリーリナックス</a>がいいです。<br /><a href="http://strawberry-linux.com/catalog/items?code=13002">乾電池でパワーLEDをつけられる部品</a>が出ました!<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhmFjs8x2XS2Nwiw1f9cIqa9nuOC3jrfoJ2HiCbdUEQtPD6rWE5VCrHIWIfbhlhJDAdb3TpPaAByL1vahwky2lSlc9nUNMfLTy-hSa6WxrUAHFCV0CE0_ajumsZnE-TclbrW_NugR6utp0/s1600-h/%E3%83%94%E3%82%AF%E3%83%81%E3%83%A3+16.png"><img style="cursor:pointer; cursor:hand;width: 256px; height: 320px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhmFjs8x2XS2Nwiw1f9cIqa9nuOC3jrfoJ2HiCbdUEQtPD6rWE5VCrHIWIfbhlhJDAdb3TpPaAByL1vahwky2lSlc9nUNMfLTy-hSa6WxrUAHFCV0CE0_ajumsZnE-TclbrW_NugR6utp0/s320/%E3%83%94%E3%82%AF%E3%83%81%E3%83%A3+16.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5355864371600742242" /></a><br />ほかに、パワーLED関係は、<a href="http://www.audio-q.com/">オーディオQ</a>も多種類あつかっていていいです。オーディオなのにLEDなのはナゾです。。久世http://www.blogger.com/profile/06898487025751982552[email protected]0tag:blogger.com,1999:blog-6697050553453132238.post-75028819953416473742009-07-07T19:30:00.004+09:002009-07-07T19:45:07.681+09:00サーボモーター<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDvSDnlT2yBL1XHH108uJC_mE6wQ3XCz1XninFPNqNDXQXCLw4lMqjl8PQa2kpjZwloZqa1UmKh3FVXn_jlgt12HCjWbdBa-tCwy_BatYcpUYDao8FXmnZPp3Oa9kUyLPiGWd1mg3qLGuA/s1600-h/%E3%82%B5%E3%83%BC%E3%83%9C%EF%BC%92.png"><img style="cursor:pointer; cursor:hand;width: 320px; height: 207px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDvSDnlT2yBL1XHH108uJC_mE6wQ3XCz1XninFPNqNDXQXCLw4lMqjl8PQa2kpjZwloZqa1UmKh3FVXn_jlgt12HCjWbdBa-tCwy_BatYcpUYDao8FXmnZPp3Oa9kUyLPiGWd1mg3qLGuA/s320/%E3%82%B5%E3%83%BC%E3%83%9C%EF%BC%92.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5355666563655638914" /></a><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgbR_73Q-Fe4IU9HW5JwdjUuZgwR5T_fIq_y5CTnuAI6IpT2_itiTIhZUP1z08utxC4DCX6dAE71jcJH3R72OWLgKI0qAazIWfeJWnT7Rqj72blD4hL7t4heqB9to-_0G8xg-FgPmxIhzRy/s1600-h/%E3%82%B5%E3%83%BC%E3%83%9C%EF%BC%91.png"><img style="cursor:pointer; cursor:hand;width: 320px; height: 198px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgbR_73Q-Fe4IU9HW5JwdjUuZgwR5T_fIq_y5CTnuAI6IpT2_itiTIhZUP1z08utxC4DCX6dAE71jcJH3R72OWLgKI0qAazIWfeJWnT7Rqj72blD4hL7t4heqB9to-_0G8xg-FgPmxIhzRy/s320/%E3%82%B5%E3%83%BC%E3%83%9C%EF%BC%91.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5355666502173245330" /></a><br /><br />サーボモーターは、だいたい1個1500円くらいします。小さいものは800円くらいから。<br />角度を制御できるモーターなので、ロボットの関節等に使われてたりします。<br />いろいろあるけど、最近は秋月電子が扱い始めて、他に比べて種類が多くてお安く買えます。<br /><a href="http://akizukidenshi.com/catalog/c/cservo/">秋月電商</a>が安いです。<br /><a href="http://strawberry-linux.com/catalog/?c=servo">ストロベリーリナックス</a>も安いです。久世http://www.blogger.com/profile/06898487025751982552[email protected]0tag:blogger.com,1999:blog-6697050553453132238.post-51206781270602520352009-07-07T19:27:00.003+09:002009-07-07T19:30:12.994+09:00ロータリーエンコーダ<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjtP0axOXz_5oUH8Td-Idbs2VtbEQbyr9V3KbNwg677RxuMGKNQYRntrkhTl_VZz315z0G8nrwjGGwkJKegnvDHt3lI65ebZNWUjV53WgAu_ACwvXAaV037Zu8OUBmYHhhE0lcBWZIZPUw_/s1600-h/%E3%83%AD%E3%83%BC%E3%82%BF%E3%83%AA%E3%83%BC%E3%82%A8%E3%83%B3%E3%82%B3%E3%83%BC%E3%83%80.png"><img style="cursor:pointer; cursor:hand;width: 305px; height: 320px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjtP0axOXz_5oUH8Td-Idbs2VtbEQbyr9V3KbNwg677RxuMGKNQYRntrkhTl_VZz315z0G8nrwjGGwkJKegnvDHt3lI65ebZNWUjV53WgAu_ACwvXAaV037Zu8OUBmYHhhE0lcBWZIZPUw_/s320/%E3%83%AD%E3%83%BC%E3%82%BF%E3%83%AA%E3%83%BC%E3%82%A8%E3%83%B3%E3%82%B3%E3%83%BC%E3%83%80.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5355662980929162162" /></a><br /><br />ボリュームのツマミで、何回転でもできる部分には、ロータリーエンコーダがつかわれてます。<br />買うときの参考に、通販のページの画像で2つだけポイントを。<br /><br />1回転の分解度が高いものほど、若干値段も高いです。<br /><br /><a href="http://www.sengoku.co.jp/mod/sgk_cart/search.php?toku=えんこ-だろ-たり&cond8=or&dai=&chu=&syo=&cond9=&k3=0&list=2&pflg=n&multi=&code=">千石電商から買えます</a>。久世http://www.blogger.com/profile/06898487025751982552[email protected]0tag:blogger.com,1999:blog-6697050553453132238.post-7517020697498688372009-07-07T17:30:00.002+09:002009-07-07T17:32:19.250+09:00センサーとLEDとモーターが組み合わさったサンプル<pre> <br /><span style="color: #777755;">//For hiraoka</span><br /><span style="color: #777755;">//Sensor and LED</span><br /><span style="color: #777755;">//and STEPMOTOR</span><br /><span style="color: #777755;">//20090707</span><br /><br /><span style="color: #777755;">//Pin</span><br /><span style="color: #996600;">int</span> ledpin1 = 8;<br /><span style="color: #996600;">int</span> ledpin2 = 9;<br /><span style="color: #996600;">int</span> ledpin3 = 10;<br /><span style="color: #996600;">int</span> ledpin4 = 13;<br /><br /><span style="color: #996600;">int</span> ST_X1=2;<br /><span style="color: #996600;">int</span> ST_X2=4;<br /><span style="color: #996600;">int</span> ST_Y1=3;<br /><span style="color: #996600;">int</span> ST_Y2=5;<br /><span style="color: #996600;">int</span> Pot=5;<br /><span style="color: #996600;">int</span> Switch=6;<br /><br /><span style="color: #777755;">//Value</span><br /><span style="color: #996600;">int</span> led1 = 0;<br /><span style="color: #996600;">int</span> led2 = 0;<br /><span style="color: #996600;">int</span> led3 = 0;<br /><span style="color: #996600;">int</span> led4 = 0;<br /><br /><span style="color: #996600;">int</span> sensor1 = 0;<br /><span style="color: #996600;">int</span> sensor2 = 0;<br /><span style="color: #996600;">int</span> sensor3 = 0;<br /><span style="color: #996600;">int</span> sensor4 = 0;<br /><br /><span style="color: #996600;">int</span> dly;<br /><span style="color: #996600;">int</span> Count=0;<br /><br /><span style="color: #CC6600;">void</span> <span style="color: #993300;"><b>setup</b></span>(){<br /> <span style="color: #996600;">pinMode</span>(ledpin1,<span style="color: #CC0000;">OUTPUT</span>);<br /> <span style="color: #996600;">pinMode</span>(ledpin2,<span style="color: #CC0000;">OUTPUT</span>);<br /> <span style="color: #996600;">pinMode</span>(ledpin3,<span style="color: #CC0000;">OUTPUT</span>);<br /> <span style="color: #996600;">pinMode</span>(ledpin4,<span style="color: #CC0000;">OUTPUT</span>);<br /> <br /> <span style="color: #996600;">pinMode</span>(ST_X1, <span style="color: #CC0000;">OUTPUT</span>);<br /> <span style="color: #996600;">pinMode</span>(ST_X2, <span style="color: #CC0000;">OUTPUT</span>);<br /> <span style="color: #996600;">pinMode</span>(ST_Y1, <span style="color: #CC0000;">OUTPUT</span>);<br /> <span style="color: #996600;">pinMode</span>(ST_Y2, <span style="color: #CC0000;">OUTPUT</span>);<br /> <span style="color: #996600;">pinMode</span>(Switch,<span style="color: #CC0000;">INPUT</span>);<br /><br /> dly = <span style="color: #996600;">analogRead</span>(Pot)/4; <br />}<br /><br /><span style="color: #CC6600;">void</span> <span style="color: #993300;"><b>loop</b></span>(){<br /> sensor1 = <span style="color: #996600;">analogRead</span>(0)/4;<br /> sensor2 = <span style="color: #996600;">analogRead</span>(1)/4;<br /> sensor3 = <span style="color: #996600;">analogRead</span>(2)/4;<br /> sensor4 = <span style="color: #996600;">analogRead</span>(5)/4;<br /><br /> led1 = sensor1;<br /> led2 = sensor2;<br /> led3 = sensor3;<br /><br /> <span style="color: #777755;">//preview</span><br /> led4 = sensor4;<br /> soft_pwm();<br /><br /> <span style="color: #CC6600;">if</span>(<span style="color: #996600;">digitalRead</span>(Switch)==1){<br /> Count=Count+1;<br /> MoveMotor(Count);<br /><br /> }<br /> <span style="color: #CC6600;">else</span>{<br /> StopMotor();<br /> }<br /> <br />}<br /><br /><span style="color: #CC6600;">void</span> soft_pwm(){<br /> <span style="color: #CC6600;">for</span>(<span style="color: #996600;">int</span> Duty=255; Duty>1; Duty--){<br /> <span style="color: #CC6600;">if</span>(Duty<=led1){<br /> <span style="color: #996600;">digitalWrite</span>(ledpin1, <span style="color: #CC0000;">HIGH</span>);<br /> }<br /> <span style="color: #CC6600;">else</span>{<br /> <span style="color: #996600;">digitalWrite</span>(ledpin1, <span style="color: #CC0000;">LOW</span>);<br /> }<br /> <span style="color: #CC6600;">if</span>(Duty<=led2){<br /> <span style="color: #996600;">digitalWrite</span>(ledpin2, <span style="color: #CC0000;">HIGH</span>);<br /> }<br /> <span style="color: #CC6600;">else</span>{<br /> <span style="color: #996600;">digitalWrite</span>(ledpin2, <span style="color: #CC0000;">LOW</span>);<br /> }<br /> <span style="color: #CC6600;">if</span>(Duty<=led3){<br /> <span style="color: #996600;">digitalWrite</span>(ledpin3, <span style="color: #CC0000;">HIGH</span>);<br /> }<br /> <span style="color: #CC6600;">else</span>{<br /> <span style="color: #996600;">digitalWrite</span>(ledpin3, <span style="color: #CC0000;">LOW</span>);<br /> }<br /> <span style="color: #CC6600;">if</span>(Duty<=led4){<br /> <span style="color: #996600;">digitalWrite</span>(ledpin4, <span style="color: #CC0000;">HIGH</span>);<br /> }<br /> <span style="color: #CC6600;">else</span>{<br /> <span style="color: #996600;">digitalWrite</span>(ledpin4, <span style="color: #CC0000;">LOW</span>);<br /> }<br /> }<br /> <span style="color: #996600;">digitalWrite</span>(ledpin1,<span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ledpin2,<span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ledpin3,<span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ledpin4,<span style="color: #CC0000;">LOW</span>);<br /><br />}<br /><br /><br /><br /><span style="color: #CC6600;">void</span> MoveMotor(<span style="color: #996600;">int</span> stp){<br /> <span style="color: #996600;">int</span> s;<br /> s=stp%8;<br /><br /> <span style="color: #CC6600;">switch</span>(s){<br /> <span style="color: #CC6600;">case</span> 0:<br /> <span style="color: #996600;">digitalWrite</span>(ST_X1, <span style="color: #CC0000;">HIGH</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_X2, <span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_Y1, <span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_Y2, <span style="color: #CC0000;">LOW</span>);<br /> dly = <span style="color: #996600;">analogRead</span>(Pot)/4;<br /> <span style="color: #996600;">delay</span>(dly);<br /> break;<br /><br /> <span style="color: #CC6600;">case</span> 1:<br /> <span style="color: #996600;">digitalWrite</span>(ST_X1, <span style="color: #CC0000;">HIGH</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_X2, <span style="color: #CC0000;">HIGH</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_Y1, <span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_Y2, <span style="color: #CC0000;">LOW</span>);<br /> dly = <span style="color: #996600;">analogRead</span>(Pot)/4;<br /> <span style="color: #996600;">delay</span>(dly);<br /> break;<br /><br /> <span style="color: #CC6600;">case</span> 2:<br /> <span style="color: #996600;">digitalWrite</span>(ST_X1, <span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_X2, <span style="color: #CC0000;">HIGH</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_Y1, <span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_Y2, <span style="color: #CC0000;">LOW</span>);<br /> dly = <span style="color: #996600;">analogRead</span>(Pot)/4;<br /> <span style="color: #996600;">delay</span>(dly);<br /> break;<br /><br /> <span style="color: #CC6600;">case</span> 3:<br /> <span style="color: #996600;">digitalWrite</span>(ST_X1, <span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_X2, <span style="color: #CC0000;">HIGH</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_Y1, <span style="color: #CC0000;">HIGH</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_Y2, <span style="color: #CC0000;">LOW</span>);<br /> dly = <span style="color: #996600;">analogRead</span>(Pot)/4;<br /> <span style="color: #996600;">delay</span>(dly);<br /> break;<br /><br /> <span style="color: #CC6600;">case</span> 4:<br /> <span style="color: #996600;">digitalWrite</span>(ST_X1, <span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_X2, <span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_Y1, <span style="color: #CC0000;">HIGH</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_Y2, <span style="color: #CC0000;">LOW</span>);<br /> dly = <span style="color: #996600;">analogRead</span>(Pot)/4;<br /> <span style="color: #996600;">delay</span>(dly);<br /> break;<br /><br /> <span style="color: #CC6600;">case</span> 5:<br /> <span style="color: #996600;">digitalWrite</span>(ST_X1, <span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_X2, <span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_Y1, <span style="color: #CC0000;">HIGH</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_Y2, <span style="color: #CC0000;">HIGH</span>);<br /> dly = <span style="color: #996600;">analogRead</span>(Pot)/4;<br /> <span style="color: #996600;">delay</span>(dly);<br /> break;<br /><br /> <span style="color: #CC6600;">case</span> 6:<br /> <span style="color: #996600;">digitalWrite</span>(ST_X1, <span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_X2, <span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_Y1, <span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_Y2, <span style="color: #CC0000;">HIGH</span>);<br /> dly = <span style="color: #996600;">analogRead</span>(Pot)/4;<br /> <span style="color: #996600;">delay</span>(dly);<br /> break;<br /><br /> <span style="color: #CC6600;">case</span> 7:<br /> <span style="color: #996600;">digitalWrite</span>(ST_X1, <span style="color: #CC0000;">HIGH</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_X2, <span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_Y1, <span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_Y2, <span style="color: #CC0000;">HIGH</span>);<br /> dly = <span style="color: #996600;">analogRead</span>(Pot)/4;<br /> <span style="color: #996600;">delay</span>(dly);<br /> break;<br /> }<br />}<br /><br /><span style="color: #CC6600;">void</span> StopMotor(){<br /> <span style="color: #996600;">digitalWrite</span>(ST_X1, <span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_X2, <span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_Y1, <span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_Y2, <span style="color: #CC0000;">LOW</span>);<br />}<br /><br /><br /></pre>久世http://www.blogger.com/profile/06898487025751982552[email protected]0tag:blogger.com,1999:blog-6697050553453132238.post-22004923215396858372009-07-07T16:47:00.000+09:002009-07-07T16:48:02.483+09:00ベアリングホルダ<a href="http://www.originalmind.co.jp/cargo5/bearingholder/">http://www.originalmind.co.jp/cargo5/bearingholder/</a>久世http://www.blogger.com/profile/06898487025751982552[email protected]0tag:blogger.com,1999:blog-6697050553453132238.post-86420462897923399722009-07-07T14:41:00.002+09:002009-07-07T14:45:08.486+09:00Arduinoと木とレーザーカットアクリルだけだと素材の幅が少ないので、木の加工例を。<br /><br /><a href="http://jp.makezine.com/blog/2009/06/wooden_mini_jansen_walker_robot_par.html">http://jp.makezine.com/blog/2009/06/wooden_mini_jansen_walker_robot_par.html</a><br /><br /><a href="http://jp.makezine.com/blog/2009/07/laser_cutting_for_3d_objects.html">http://jp.makezine.com/blog/2009/07/laser_cutting_for_3d_objects.html</a>久世http://www.blogger.com/profile/06898487025751982552[email protected]0tag:blogger.com,1999:blog-6697050553453132238.post-91122500387202477522009-07-07T11:39:00.003+09:002009-07-07T17:32:52.672+09:00センサーとLEDで確認するプログラムサンプル<pre> <br /><span style="color: #777755;">//For hiraoka</span><br /><span style="color: #777755;">//Sensor and LED</span><br /><span style="color: #777755;">//20090707</span><br /><br /><span style="color: #777755;">//Pin</span><br /><span style="color: #996600;">int</span> ledpin1 = 8;<br /><span style="color: #996600;">int</span> ledpin2 = 9;<br /><span style="color: #996600;">int</span> ledpin3 = 12;<br /><span style="color: #996600;">int</span> ledpin4 = 11;<br /><span style="color: #996600;">int</span> ledpin5 = 13;<br /><br /><span style="color: #777755;">//Value</span><br /><span style="color: #996600;">int</span> led1 = 0;<br /><span style="color: #996600;">int</span> led2 = 0;<br /><span style="color: #996600;">int</span> led3 = 0;<br /><span style="color: #996600;">int</span> led4 = 0;<br /><span style="color: #996600;">int</span> led5 = 0;<br /><span style="color: #996600;">int</span> sensor1 = 0;<br /><span style="color: #996600;">int</span> sensor2 = 0;<br /><span style="color: #996600;">int</span> sensor3 = 0;<br /><span style="color: #996600;">int</span> sensor4 = 0;<br /><span style="color: #996600;">int</span> sensor5 = 0;<br /><br /><span style="color: #CC6600;">void</span> <span style="color: #993300;"><b>setup</b></span>(){<br /> <span style="color: #996600;">pinMode</span>(ledpin1,<span style="color: #CC0000;">OUTPUT</span>);<br /> <span style="color: #996600;">pinMode</span>(ledpin2,<span style="color: #CC0000;">OUTPUT</span>);<br /> <span style="color: #996600;">pinMode</span>(ledpin3,<span style="color: #CC0000;">OUTPUT</span>);<br /> <span style="color: #996600;">pinMode</span>(ledpin4,<span style="color: #CC0000;">OUTPUT</span>);<br /> <span style="color: #996600;">pinMode</span>(ledpin5,<span style="color: #CC0000;">OUTPUT</span>);<br />}<br /><br /><span style="color: #CC6600;">void</span> <span style="color: #993300;"><b>loop</b></span>(){<br /> sensor1 = <span style="color: #996600;">analogRead</span>(0);<br /> sensor2 = <span style="color: #996600;">analogRead</span>(1);<br /> sensor3 = <span style="color: #996600;">analogRead</span>(2);<br /> sensor4 = <span style="color: #996600;">analogRead</span>(3);<br /> sensor5 = <span style="color: #996600;">analogRead</span>(5);<br /><br /> led1 = sensor1;<br /> led2 = sensor2;<br /> led3 = sensor3;<br /> led4 = sensor4;<br /> led5 = sensor5;<br /><br /> soft_pwm();<br />}<br /><br /><span style="color: #CC6600;">void</span> soft_pwm(){<br /> <span style="color: #CC6600;">for</span>(<span style="color: #996600;">int</span> Duty=1023; Duty>1; Duty--){<br /> <span style="color: #CC6600;">if</span>(Duty<=led1){<br /> <span style="color: #996600;">digitalWrite</span>(ledpin1, <span style="color: #CC0000;">HIGH</span>);<br /> }<br /> <span style="color: #CC6600;">else</span>{<br /> <span style="color: #996600;">digitalWrite</span>(ledpin1, <span style="color: #CC0000;">LOW</span>);<br /> }<br /> <span style="color: #CC6600;">if</span>(Duty<=led2){<br /> <span style="color: #996600;">digitalWrite</span>(ledpin2, <span style="color: #CC0000;">HIGH</span>);<br /> }<br /> <span style="color: #CC6600;">else</span>{<br /> <span style="color: #996600;">digitalWrite</span>(ledpin2, <span style="color: #CC0000;">LOW</span>);<br /> }<br /> <span style="color: #CC6600;">if</span>(Duty<=led3){<br /> <span style="color: #996600;">digitalWrite</span>(ledpin3, <span style="color: #CC0000;">HIGH</span>);<br /> }<br /> <span style="color: #CC6600;">else</span>{<br /> <span style="color: #996600;">digitalWrite</span>(ledpin3, <span style="color: #CC0000;">LOW</span>);<br /> }<br /> <span style="color: #CC6600;">if</span>(Duty<=led4){<br /> <span style="color: #996600;">digitalWrite</span>(ledpin4, <span style="color: #CC0000;">HIGH</span>);<br /> }<br /> <span style="color: #CC6600;">else</span>{<br /> <span style="color: #996600;">digitalWrite</span>(ledpin4, <span style="color: #CC0000;">LOW</span>);<br /> }<br /> <span style="color: #CC6600;">if</span>(Duty<=led5){<br /> <span style="color: #996600;">digitalWrite</span>(ledpin5, <span style="color: #CC0000;">HIGH</span>);<br /> }<br /> <span style="color: #CC6600;">else</span>{<br /> <span style="color: #996600;">digitalWrite</span>(ledpin5, <span style="color: #CC0000;">LOW</span>);<br /> }<br /> }<br /> <span style="color: #996600;">digitalWrite</span>(ledpin1,<span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ledpin2,<span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ledpin3,<span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ledpin4,<span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ledpin5,<span style="color: #CC0000;">LOW</span>);<br /><br />}<br /><br /><br /></pre>久世http://www.blogger.com/profile/06898487025751982552[email protected]0tag:blogger.com,1999:blog-6697050553453132238.post-4695320778091514102009-06-29T12:48:00.001+09:002009-06-29T12:50:09.149+09:00でわくんのプログラムサンプル<pre> <br /><span style="color: #777755;">/*----</span><br /><span style="color: #777755;">ボタン押してない</span><br /><span style="color: #777755;">・モーター回らない</span><br /><span style="color: #777755;">・LEDも光らない</span><br /><br /><span style="color: #777755;">ボタン押す</span><br /><span style="color: #777755;">・モーター回る</span><br /><span style="color: #777755;">・6つのLEDの位置を時計としてみると、</span><br /><span style="color: #777755;">a:12時6時が光り</span><br /><span style="color: #777755;">b:10時4時が光り</span><br /><span style="color: #777755;">c:8時と2時が光り</span><br /><span style="color: #777755;">d:最後に6つ全部が光る</span><br /><span style="color: #777755;">a~d繰り返し</span><br /><br /><span style="color: #777755;">もう一度スイッチを押すとモーターもLEDも止まる。</span><br /><span style="color: #777755;">LEDの色は青でお願いします</span><br /><span style="color: #777755;">----*/</span><br /><br /><span style="color: #777755;">//PinAssign</span><br /><span style="color: #996600;">int</span> ST_X1=2;<br /><span style="color: #996600;">int</span> ST_X2=4;<br /><span style="color: #996600;">int</span> ST_Y1=3;<br /><span style="color: #996600;">int</span> ST_Y2=5;<br /><span style="color: #996600;">int</span> ledPin=13;<br /><br /><span style="color: #996600;">int</span> LED1=8;<br /><span style="color: #996600;">int</span> LED2=9;<br /><span style="color: #996600;">int</span> LED3=10;<br /><span style="color: #996600;">int</span> LED4=11;<br /><span style="color: #996600;">int</span> LED5=12;<br /><span style="color: #996600;">int</span> LED6=13;<br /> <br /> <br /><span style="color: #777755;">//PotentionMeter</span><br /><span style="color: #996600;">int</span> Pot=5;<br /><span style="color: #777755;">//Switch</span><br /><span style="color: #996600;">int</span> Switch=6;<br /><span style="color: #996600;">int</span> dly;<br /><span style="color: #CC6600;">signed</span> <span style="color: #996600;">int</span> Count=0;<br /><span style="color: #CC6600;">signed</span> <span style="color: #996600;">int</span> Dimmention=1;<br /><span style="color: #996600;">int</span> switch_status;<br /><br /> <br /><span style="color: #CC6600;">void</span> <span style="color: #993300;"><b>setup</b></span>(){<br /> <span style="color: #996600;">pinMode</span>(ST_X1, <span style="color: #CC0000;">OUTPUT</span>);<br /> <span style="color: #996600;">pinMode</span>(ST_X2, <span style="color: #CC0000;">OUTPUT</span>);<br /> <span style="color: #996600;">pinMode</span>(ST_Y1, <span style="color: #CC0000;">OUTPUT</span>);<br /> <span style="color: #996600;">pinMode</span>(ST_Y2, <span style="color: #CC0000;">OUTPUT</span>);<br /> <span style="color: #996600;">pinMode</span>(ledPin, <span style="color: #CC0000;">OUTPUT</span>);<br /> <span style="color: #777755;">//POT is Default AnalogInput</span><br /> <span style="color: #996600;">pinMode</span>(Switch,<span style="color: #CC0000;">INPUT</span>);<br /> dly = <span style="color: #996600;">analogRead</span>(Pot)/4;<br /> switch_status=0;<br />}<br /> <br /> <br /><span style="color: #CC6600;">void</span> <span style="color: #993300;"><b>loop</b></span>(){<br /> <span style="color: #CC6600;">if</span>(<span style="color: #996600;">digitalRead</span>(Switch)==1){<br /> <span style="color: #CC6600;">if</span>(switch_status==0){<br /> switch_status=1;<br /> }<span style="color: #CC6600;">else</span>{<br /> switch_status=0;<br /> }<br /> }<br /> <span style="color: #CC6600;">if</span>(switch_status==1){<br /> Count=Count+1;<br /> <span style="color: #CC6600;">if</span>(Count>96){<br /> Count=0;<br /> }<span style="color: #CC6600;">else</span> <span style="color: #CC6600;">if</span>(Count<0){<br /> Count=96;<br /> }<br /> LightLED(Count);<br /> MoveMotor(Count);<br /> }<span style="color: #CC6600;">else</span>{<br /> StopLED();<br /> StopMotor();<br /> }<br />}<br /><br /><span style="color: #CC6600;">void</span> LightLED(<span style="color: #996600;">int</span> stp){<br /> <span style="color: #996600;">int</span> s;<br /> s=(stp/10)%6;<br /> <br /> <span style="color: #CC6600;">switch</span>(s){<br /> <span style="color: #CC6600;">case</span> 0:<br /> <span style="color: #996600;">digitalWrite</span>(LED1,<span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(LED2,<span style="color: #CC0000;">HIGH</span>);<br /> <span style="color: #996600;">digitalWrite</span>(LED3,<span style="color: #CC0000;">HIGH</span>);<br /> <span style="color: #996600;">digitalWrite</span>(LED4,<span style="color: #CC0000;">HIGH</span>);<br /> <span style="color: #996600;">digitalWrite</span>(LED5,<span style="color: #CC0000;">HIGH</span>);<br /> <span style="color: #996600;">digitalWrite</span>(LED6,<span style="color: #CC0000;">HIGH</span>);<br /> break; <br /> <span style="color: #CC6600;">case</span> 1:<br /> <span style="color: #996600;">digitalWrite</span>(LED1,<span style="color: #CC0000;">HIGH</span>);<br /> <span style="color: #996600;">digitalWrite</span>(LED2,<span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(LED3,<span style="color: #CC0000;">HIGH</span>);<br /> <span style="color: #996600;">digitalWrite</span>(LED4,<span style="color: #CC0000;">HIGH</span>);<br /> <span style="color: #996600;">digitalWrite</span>(LED5,<span style="color: #CC0000;">HIGH</span>);<br /> <span style="color: #996600;">digitalWrite</span>(LED6,<span style="color: #CC0000;">HIGH</span>);<br /> break; <br /> <span style="color: #CC6600;">case</span> 2:<br /> <span style="color: #996600;">digitalWrite</span>(LED1,<span style="color: #CC0000;">HIGH</span>);<br /> <span style="color: #996600;">digitalWrite</span>(LED2,<span style="color: #CC0000;">HIGH</span>);<br /> <span style="color: #996600;">digitalWrite</span>(LED3,<span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(LED4,<span style="color: #CC0000;">HIGH</span>);<br /> <span style="color: #996600;">digitalWrite</span>(LED5,<span style="color: #CC0000;">HIGH</span>);<br /> <span style="color: #996600;">digitalWrite</span>(LED6,<span style="color: #CC0000;">HIGH</span>);<br /> break; <br /> <span style="color: #CC6600;">case</span> 3:<br /> <span style="color: #996600;">digitalWrite</span>(LED1,<span style="color: #CC0000;">HIGH</span>);<br /> <span style="color: #996600;">digitalWrite</span>(LED2,<span style="color: #CC0000;">HIGH</span>);<br /> <span style="color: #996600;">digitalWrite</span>(LED3,<span style="color: #CC0000;">HIGH</span>);<br /> <span style="color: #996600;">digitalWrite</span>(LED4,<span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(LED5,<span style="color: #CC0000;">HIGH</span>);<br /> <span style="color: #996600;">digitalWrite</span>(LED6,<span style="color: #CC0000;">HIGH</span>);<br /> break; <br /> <span style="color: #CC6600;">case</span> 4:<br /> <span style="color: #996600;">digitalWrite</span>(LED1,<span style="color: #CC0000;">HIGH</span>);<br /> <span style="color: #996600;">digitalWrite</span>(LED2,<span style="color: #CC0000;">HIGH</span>);<br /> <span style="color: #996600;">digitalWrite</span>(LED3,<span style="color: #CC0000;">HIGH</span>);<br /> <span style="color: #996600;">digitalWrite</span>(LED4,<span style="color: #CC0000;">HIGH</span>);<br /> <span style="color: #996600;">digitalWrite</span>(LED5,<span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(LED6,<span style="color: #CC0000;">HIGH</span>);<br /> break; <br /> <span style="color: #CC6600;">case</span> 5:<br /> <span style="color: #996600;">digitalWrite</span>(LED1,<span style="color: #CC0000;">HIGH</span>);<br /> <span style="color: #996600;">digitalWrite</span>(LED2,<span style="color: #CC0000;">HIGH</span>);<br /> <span style="color: #996600;">digitalWrite</span>(LED3,<span style="color: #CC0000;">HIGH</span>);<br /> <span style="color: #996600;">digitalWrite</span>(LED4,<span style="color: #CC0000;">HIGH</span>);<br /> <span style="color: #996600;">digitalWrite</span>(LED5,<span style="color: #CC0000;">HIGH</span>);<br /> <span style="color: #996600;">digitalWrite</span>(LED6,<span style="color: #CC0000;">LOW</span>);<br /> break; <br /> }<br />}<br /><br /><span style="color: #CC6600;">void</span> StopLED(){<br /> <span style="color: #996600;">digitalWrite</span>(LED1,<span style="color: #CC0000;">HIGH</span>);<br /> <span style="color: #996600;">digitalWrite</span>(LED2,<span style="color: #CC0000;">HIGH</span>);<br /> <span style="color: #996600;">digitalWrite</span>(LED3,<span style="color: #CC0000;">HIGH</span>);<br /> <span style="color: #996600;">digitalWrite</span>(LED4,<span style="color: #CC0000;">HIGH</span>);<br /> <span style="color: #996600;">digitalWrite</span>(LED5,<span style="color: #CC0000;">HIGH</span>);<br /> <span style="color: #996600;">digitalWrite</span>(LED6,<span style="color: #CC0000;">HIGH</span>);<br />}<br /><br /><span style="color: #CC6600;">void</span> MoveMotor(<span style="color: #996600;">int</span> stp){<br /> <span style="color: #996600;">int</span> s;<br /> s=stp%8;<br /><br /> <span style="color: #CC6600;">switch</span>(s){<br /> <span style="color: #CC6600;">case</span> 0:<br /> <span style="color: #996600;">digitalWrite</span>(ST_X1, <span style="color: #CC0000;">HIGH</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_X2, <span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_Y1, <span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_Y2, <span style="color: #CC0000;">LOW</span>);<br /> dly = <span style="color: #996600;">analogRead</span>(Pot)/4;<br /> <span style="color: #996600;">delay</span>(dly);<br /> break;<br /><br /> <span style="color: #CC6600;">case</span> 1:<br /> <span style="color: #996600;">digitalWrite</span>(ST_X1, <span style="color: #CC0000;">HIGH</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_X2, <span style="color: #CC0000;">HIGH</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_Y1, <span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_Y2, <span style="color: #CC0000;">LOW</span>);<br /> dly = <span style="color: #996600;">analogRead</span>(Pot)/4;<br /> <span style="color: #996600;">delay</span>(dly);<br /> break;<br /><br /> <span style="color: #CC6600;">case</span> 2:<br /> <span style="color: #996600;">digitalWrite</span>(ST_X1, <span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_X2, <span style="color: #CC0000;">HIGH</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_Y1, <span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_Y2, <span style="color: #CC0000;">LOW</span>);<br /> dly = <span style="color: #996600;">analogRead</span>(Pot)/4;<br /> <span style="color: #996600;">delay</span>(dly);<br /> break;<br /><br /> <span style="color: #CC6600;">case</span> 3:<br /> <span style="color: #996600;">digitalWrite</span>(ST_X1, <span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_X2, <span style="color: #CC0000;">HIGH</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_Y1, <span style="color: #CC0000;">HIGH</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_Y2, <span style="color: #CC0000;">LOW</span>);<br /> dly = <span style="color: #996600;">analogRead</span>(Pot)/4;<br /> <span style="color: #996600;">delay</span>(dly);<br /> break;<br /><br /> <span style="color: #CC6600;">case</span> 4:<br /> <span style="color: #996600;">digitalWrite</span>(ST_X1, <span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_X2, <span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_Y1, <span style="color: #CC0000;">HIGH</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_Y2, <span style="color: #CC0000;">LOW</span>);<br /> dly = <span style="color: #996600;">analogRead</span>(Pot)/4;<br /> <span style="color: #996600;">delay</span>(dly);<br /> break;<br /><br /> <span style="color: #CC6600;">case</span> 5:<br /> <span style="color: #996600;">digitalWrite</span>(ST_X1, <span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_X2, <span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_Y1, <span style="color: #CC0000;">HIGH</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_Y2, <span style="color: #CC0000;">HIGH</span>);<br /> dly = <span style="color: #996600;">analogRead</span>(Pot)/4;<br /> <span style="color: #996600;">delay</span>(dly);<br /> break;<br /><br /> <span style="color: #CC6600;">case</span> 6:<br /> <span style="color: #996600;">digitalWrite</span>(ST_X1, <span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_X2, <span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_Y1, <span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_Y2, <span style="color: #CC0000;">HIGH</span>);<br /> dly = <span style="color: #996600;">analogRead</span>(Pot)/4;<br /> <span style="color: #996600;">delay</span>(dly);<br /> break;<br /><br /> <span style="color: #CC6600;">case</span> 7:<br /> <span style="color: #996600;">digitalWrite</span>(ST_X1, <span style="color: #CC0000;">HIGH</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_X2, <span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_Y1, <span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_Y2, <span style="color: #CC0000;">HIGH</span>);<br /> dly = <span style="color: #996600;">analogRead</span>(Pot)/4;<br /> <span style="color: #996600;">delay</span>(dly);<br /> break;<br /> }<br />}<br /><br /> <br /><span style="color: #CC6600;">void</span> StopMotor(){<br /> <span style="color: #996600;">digitalWrite</span>(ST_X1, <span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_X2, <span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_Y1, <span style="color: #CC0000;">LOW</span>);<br /> <span style="color: #996600;">digitalWrite</span>(ST_Y2, <span style="color: #CC0000;">LOW</span>);<br />}<br /><br /><br /></pre>久世http://www.blogger.com/profile/06898487025751982552[email protected]0tag:blogger.com,1999:blog-6697050553453132238.post-90625001278253923592009-06-24T17:01:00.004+09:002009-06-29T12:50:46.749+09:00プログラムサンプル<pre> <br /><span style="color: #777755;">//pin select</span><br /><span style="color: #996600;">int</span> MOTOR =11;<br /><span style="color: #996600;">int</span> LED=10;<br /><br /><span style="color: #777755;">//サウンドのレベル用変数</span><br /><span style="color: #996600;">int</span> sound_level;<br /><br /><span style="color: #777755;">//サウンド感度調整ツマミ用変数</span><br /><span style="color: #996600;">int</span> analog0;<br /><br /><span style="color: #777755;">//モーターの回る時間調整ツマミ用変数</span><br /><span style="color: #996600;">int</span> analog1;<br /><br /><span style="color: #777755;">//LEDの明るさ用変数</span><br /><span style="color: #996600;">int</span> led_blight;<br /><br /><br /><span style="color: #777755;">//forループ用変数</span><br /><span style="color: #996600;">int</span> j;<br /><br /><span style="color: #777755;">//セットアップ</span><br /><span style="color: #CC6600;">void</span> <span style="color: #993300;"><b>setup</b></span>(){<br /> <span style="color: #777755;">//モーターピンをアウトプット(電気が出るように)</span><br /> <span style="color: #996600;">pinMode</span>(MOTOR,<span style="color: #CC0000;">OUTPUT</span>);<br /> <span style="color: #777755;">//LEDピンもアウトプット(電気が出るように)</span><br /> <span style="color: #996600;">pinMode</span>(LED,<span style="color: #CC0000;">OUTPUT</span>);<br />}<br /><br /><br /><br /><span style="color: #777755;">//メインループ</span><br /><span style="color: #CC6600;">void</span> <span style="color: #993300;"><b>loop</b></span>(){<br /><br /> <span style="color: #777755;">//サウンドレベルを読む(analog5ピン)</span><br /> sound_level=<span style="color: #996600;">analogRead</span>(5);<br /> <span style="color: #777755;">//サウンド感度調整ツマミを読む(analog3ピン)</span><br /> analog0=<span style="color: #996600;">analogRead</span>(3);<br /><br /><br /> <span style="color: #777755;">//もしも、サウンドレベルが感度調整ツマミより大きくなったら、</span><br /> <span style="color: #CC6600;">if</span>(sound_level>analog0){<br /><br /> <span style="color: #777755;">//モーターに電気を流す(回転)</span><br /> <span style="color: #996600;">digitalWrite</span>(MOTOR,<span style="color: #CC0000;">HIGH</span>);<br /> <br /> <span style="color: #777755;">//LEDの明るさ変数を最大にする</span><br /> led_blight=1023;<br /> <br /> <span style="color: #777755;">//モーターの回転時間調整ツマミを読む(alanog4ピン)</span><br /> analog1=<span style="color: #996600;">analogRead</span>(4);<br /><br /> <span style="color: #777755;">//モーターの回転調整の数値の回数だけ、delay(1)を繰り返す</span><br /> <span style="color: #CC6600;">for</span>(j=0; j < analog1; j++){<br /> <span style="color: #996600;">delay</span>(1);<br /> }<br /><br /> <span style="color: #777755;">//モーターの電気をとめる(回転停止)</span><br /> <span style="color: #996600;">digitalWrite</span>(MOTOR,<span style="color: #CC0000;">LOW</span>); <br /> <br /> <span style="color: #777755;">//もう一度、モーター回転時間調整ツマミを読む</span><br /> <span style="color: #777755;">//その時間を今度は4で割る</span><br /> analog1=<span style="color: #996600;">analogRead</span>(4)/4;<br /><br /> <span style="color: #777755;">//回転時間調整ツマミを4で割った回数だけ、delay(1)を繰り返す </span><br /> <span style="color: #CC6600;">for</span>(j=0; j < analog1; j++){<br /> <span style="color: #996600;">delay</span>(1);<br /> }<br /><br /> }<br /> <span style="color: #777755;">//そうじゃないとき(サウンドレベルが感度調整ツマミより大きくないとき)</span><br /> <span style="color: #CC6600;">else</span>{<br /> <span style="color: #777755;">//LEDの明るさ変数に、0.99を掛け算して、徐々に減らす</span><br /> <span style="color: #777755;">//(じんわりと消えていくような場合のテクです)</span><br /> led_blight*=0.99;<br /> <span style="color: #777755;">//モーターの電気をストップ(回転停止)</span><br /> <span style="color: #996600;">digitalWrite</span>(MOTOR,<span style="color: #CC0000;">LOW</span>); <br /> }<br /><br /> <span style="color: #777755;">//LEDの明るさを実際にピンに反映させる</span><br /> <span style="color: #996600;">analogWrite</span>(LED,1023-led_blight); <br />}<br /><br /><br /></pre>久世http://www.blogger.com/profile/06898487025751982552[email protected]0tag:blogger.com,1999:blog-6697050553453132238.post-72708327013442979872009-06-20T12:21:00.007+09:002009-06-29T12:50:56.816+09:00参考リンク6月17日(水)の授業でみんなの相談をもとに調べたサイトです。<br />関係ない人も今後のために見てみてください。<br /><br /><br /><a href="http://jp.makezine.com/blog/2009/06/wooden_mini_jansen_walker_robot_par.html">木製ヤンセンウォーカー</a><br /><a href="http://4volt.com/Projects/Jansen/">アクリル+Arduinoでヤンセン(カットデータ付き!)</a><br /><br /><a href="http://www.kyoto-np.co.jp/kp/rensai/fushigi/f_10.html">ペットボトルにいれた人形が上下するおもちゃのしくみ</a><br /><br /><a href="http://www2e.biglobe.ne.jp/~shinzo/jikken/jiseitai/jiseitai.html">コピーのトナーでつくる磁性流体</a><br /><br /><a href="http://www.hakko.co.jp/expe/new/exnew0601.htm">熱に関する実験</a><br /><a href="http://www.hakko.co.jp/tech-netsu.htm">熱の実験室</a><br /><a href="http://www.hakko.co.jp/contest/contest_index.html">熱の実験コンテスト(これおもしろい!)</a><br /><br /><a href="http://jp.makezine.com/blog/2009/06/arduino_segment_on_the_bbc.html">BBCでArduinoがとりあげられたそうです〜</a><br /><br /><a href="http://blog.makezine.com/archive/2009/06/minty_kalimba.html?CMP=OTC-0D6B48984890">カリンバ</a>久世http://www.blogger.com/profile/06898487025751982552[email protected]0tag:blogger.com,1999:blog-6697050553453132238.post-67995601309688514312009-06-02T15:34:00.003+09:002009-06-29T12:51:09.316+09:00実用的なステッピングモーターのプログラム その410回押したら、一定ステップ回転する。<br />----<br />//StepMotor sample<br />//2009.6.2<br /> <br />//PinAssign<br />int ST_X1=2;<br />int ST_X2=4;<br />int ST_Y1=3;<br />int ST_Y2=5;<br />int ledPin=13;<br /> <br />//PotentionMeter<br />int Pot=5;<br />//Switch<br />int Switch=6;<br />int dly;<br />signed int Count=0;<br />signed int Dimmention=1;<br />int Switch_status=0;<br />int Switch_count=0;<br /><br /> <br />void setup(){<br /> pinMode(ST_X1, OUTPUT);<br /> pinMode(ST_X2, OUTPUT);<br /> pinMode(ST_Y1, OUTPUT);<br /> pinMode(ST_Y2, OUTPUT);<br /> pinMode(ledPin, OUTPUT);<br /> //POT is Default AnalogInput<br /> pinMode(Switch,INPUT);<br /> dly = analogRead(Pot)/4;<br />}<br /> <br />void loop(){<br /> if(digitalRead(Switch)==1){<br /> //Debounce<br /> delay(25);<br /> if(Switch_status==0){<br /> Dimmention=1;<br /> Switch_status=1;<br /> Switch_count=Switch_count+1;<br /> digitalWrite(ledPin, HIGH);<br /> }<br /> }else{<br /> if(Switch_status==1){ <br /> Dimmention=-1;<br /> Switch_status=0;<br /> digitalWrite(ledPin, LOW);<br /> }<br /> }<br /> <br /> if(Switch_count>=10){<br /> Switch_count=0;<br /> for(Count=0; Count<96; Count=Count+1){ <br /> MoveMotor(Count);<br /> }<br /> }<br /> <br />}<br /><br /><br />void MoveMotor(int stp){<br /> int s;<br /> s=stp%8;<br /><br /> switch(s){<br /> case 0:<br /> digitalWrite(ST_X1, HIGH);<br /> digitalWrite(ST_X2, LOW);<br /> digitalWrite(ST_Y1, LOW);<br /> digitalWrite(ST_Y2, LOW);<br /> dly = analogRead(Pot)/4;<br /> delay(dly);<br /> break;<br /><br /> case 1:<br /> digitalWrite(ST_X1, HIGH);<br /> digitalWrite(ST_X2, HIGH);<br /> digitalWrite(ST_Y1, LOW);<br /> digitalWrite(ST_Y2, LOW);<br /> dly = analogRead(Pot)/4;<br /> delay(dly);<br /> break;<br /><br /> case 2:<br /> digitalWrite(ST_X1, LOW);<br /> digitalWrite(ST_X2, HIGH);<br /> digitalWrite(ST_Y1, LOW);<br /> digitalWrite(ST_Y2, LOW);<br /> dly = analogRead(Pot)/4;<br /> delay(dly);<br /> break;<br /><br /> case 3:<br /> digitalWrite(ST_X1, LOW);<br /> digitalWrite(ST_X2, HIGH);<br /> digitalWrite(ST_Y1, HIGH);<br /> digitalWrite(ST_Y2, LOW);<br /> dly = analogRead(Pot)/4;<br /> delay(dly);<br /> break;<br /><br /> case 4:<br /> digitalWrite(ST_X1, LOW);<br /> digitalWrite(ST_X2, LOW);<br /> digitalWrite(ST_Y1, HIGH);<br /> digitalWrite(ST_Y2, LOW);<br /> dly = analogRead(Pot)/4;<br /> delay(dly);<br /> break;<br /><br /> case 5:<br /> digitalWrite(ST_X1, LOW);<br /> digitalWrite(ST_X2, LOW);<br /> digitalWrite(ST_Y1, HIGH);<br /> digitalWrite(ST_Y2, HIGH);<br /> dly = analogRead(Pot)/4;<br /> delay(dly);<br /> break;<br /><br /> case 6:<br /> digitalWrite(ST_X1, LOW);<br /> digitalWrite(ST_X2, LOW);<br /> digitalWrite(ST_Y1, LOW);<br /> digitalWrite(ST_Y2, HIGH);<br /> dly = analogRead(Pot)/4;<br /> delay(dly);<br /> break;<br /><br /> case 7:<br /> digitalWrite(ST_X1, HIGH);<br /> digitalWrite(ST_X2, LOW);<br /> digitalWrite(ST_Y1, LOW);<br /> digitalWrite(ST_Y2, HIGH);<br /> dly = analogRead(Pot)/4;<br /> delay(dly);<br /> break;<br /> }<br />}<br /> <br />void StopMotor(){<br /> digitalWrite(ST_X1, LOW);<br /> digitalWrite(ST_X2, LOW);<br /> digitalWrite(ST_Y1, LOW);<br /> digitalWrite(ST_Y2, LOW);<br />}久世http://www.blogger.com/profile/06898487025751982552[email protected]0tag:blogger.com,1999:blog-6697050553453132238.post-72343101630256980772009-06-02T12:30:00.002+09:002009-06-29T12:51:25.265+09:00マリオの音が鳴るプログラム(おまけ)ちょっと気分転換で。<br /><br />ハンダ付けの上からスピーカーをつけるのが難しいので、Arduinoから基板を外してください。<br />スピーカーのピンを、10番ピンと、GNDピンに差し込んで準備完了。<br /><br />----<br />int SpeakerPin = 10;<br />unsigned int i;<br /><br />unsigned int j;<br /><br />void setup(){<br /> pinMode(SpeakerPin, OUTPUT);<br />}<br /><br />void mario_1up(){<br /> for (i=0; i<97; i++){<br /> digitalWrite(SpeakerPin,HIGH);<br /> delayMicroseconds(379);<br /> digitalWrite(SpeakerPin,LOW);<br /> delayMicroseconds(379);<br /> }<br /> for (i=0; i<235; i++){<br /> digitalWrite(SpeakerPin,HIGH);<br /> delayMicroseconds(319);<br /> digitalWrite(SpeakerPin,LOW);<br /> delayMicroseconds(319);<br /> }<br /> for (i=0; i<396; i++){<br /> digitalWrite(SpeakerPin,HIGH);<br /> delayMicroseconds(189);<br /> digitalWrite(SpeakerPin,LOW);<br /> delayMicroseconds(189);<br /> }<br /> for (i=0; i<315; i++){<br /> digitalWrite(SpeakerPin,HIGH);<br /> delayMicroseconds(238);<br /> digitalWrite(SpeakerPin,LOW);<br /> delayMicroseconds(238);<br /> }<br /> for (i=0; i<353; i++){<br /> digitalWrite(SpeakerPin,HIGH);<br /> delayMicroseconds(212);<br /> digitalWrite(SpeakerPin,LOW);<br /> delayMicroseconds(212);<br /> }<br /> for (i=0; i<471; i++){<br /> digitalWrite(SpeakerPin,HIGH);<br /> delayMicroseconds(159);<br /> digitalWrite(SpeakerPin,LOW);<br /> delayMicroseconds(159);<br /> }<br /> <br />}<br /><br />void get_coin(){<br /> for (i=0; i<250; i++){<br /> digitalWrite(SpeakerPin,HIGH);<br /> delayMicroseconds(253);<br /> digitalWrite(SpeakerPin,LOW);<br /> delayMicroseconds(253);<br /> }<br /> for (i=0; i<500; i++){<br /> digitalWrite(SpeakerPin,HIGH);<br /> delayMicroseconds(189);<br /> digitalWrite(SpeakerPin,LOW);<br /> delayMicroseconds(189);<br /> }<br /> delay(50);<br /> <br />}<br /><br /><br />void loop(){<br /> <br /> for(j=0; j<10; j++){<br /> get_coin();<br /> delay(50);<br /> }<br /><br /> mario_1up();<br /> delay(500);<br /><br />}久世http://www.blogger.com/profile/06898487025751982552[email protected]0tag:blogger.com,1999:blog-6697050553453132238.post-61566374832270473812009-06-02T12:28:00.001+09:002009-06-29T12:51:34.925+09:00実用的なステッピングモーターのプログラム その3スイッチを押して、回転方向を切り替えます。<br /><br /><a href="http://www.kuze.jp/geikoudai/jikken2009spring/page08.html">こちらで解説</a><br /><br />----<br />//StepMotor sample<br />//2009.6.2<br /> <br />//PinAssign<br />int ST_X1=2;<br />int ST_X2=4;<br />int ST_Y1=3;<br />int ST_Y2=5;<br />int ledPin=13;<br /> <br />//PotentionMeter<br />int Pot=5;<br />//Switch<br />int Switch=6;<br />int dly;<br />signed int Count=0;<br />signed int Dimmention=1;<br />int Switch_status=0;<br /><br /> <br />void setup(){<br /> pinMode(ST_X1, OUTPUT);<br /> pinMode(ST_X2, OUTPUT);<br /> pinMode(ST_Y1, OUTPUT);<br /> pinMode(ST_Y2, OUTPUT);<br /> pinMode(ledPin, OUTPUT);<br /> //POT is Default AnalogInput<br /> pinMode(Switch,INPUT);<br /> dly = analogRead(Pot)/4;<br />}<br /> <br />void loop(){<br /> if(digitalRead(Switch)==1){<br /> if(Switch_status==0){<br /> Dimmention=1;<br /> Switch_status=1;<br /> }<br /> }else{<br /> if(Switch_status==1){ <br /> Dimmention=-1;<br /> Switch_status=0;<br /> }<br /> }<br /> <br /> Count=Count+Dimmention;<br /> <br /> if(Count>96){<br /> Count=0;<br /> }else if(Count<0){<br /> Count=96;<br /> }<br /> <br /> MoveMotor(Count);<br /> <br />}<br /><br /><br />void MoveMotor(int stp){<br /> int s;<br /> s=stp%8;<br /><br /> switch(s){<br /> case 0:<br /> digitalWrite(ST_X1, HIGH);<br /> digitalWrite(ST_X2, LOW);<br /> digitalWrite(ST_Y1, LOW);<br /> digitalWrite(ST_Y2, LOW);<br /> dly = analogRead(Pot)/4;<br /> delay(dly);<br /> break;<br /><br /> case 1:<br /> digitalWrite(ST_X1, HIGH);<br /> digitalWrite(ST_X2, HIGH);<br /> digitalWrite(ST_Y1, LOW);<br /> digitalWrite(ST_Y2, LOW);<br /> dly = analogRead(Pot)/4;<br /> delay(dly);<br /> break;<br /><br /> case 2:<br /> digitalWrite(ST_X1, LOW);<br /> digitalWrite(ST_X2, HIGH);<br /> digitalWrite(ST_Y1, LOW);<br /> digitalWrite(ST_Y2, LOW);<br /> dly = analogRead(Pot)/4;<br /> delay(dly);<br /> break;<br /><br /> case 3:<br /> digitalWrite(ST_X1, LOW);<br /> digitalWrite(ST_X2, HIGH);<br /> digitalWrite(ST_Y1, HIGH);<br /> digitalWrite(ST_Y2, LOW);<br /> dly = analogRead(Pot)/4;<br /> delay(dly);<br /> break;<br /><br /> case 4:<br /> digitalWrite(ST_X1, LOW);<br /> digitalWrite(ST_X2, LOW);<br /> digitalWrite(ST_Y1, HIGH);<br /> digitalWrite(ST_Y2, LOW);<br /> dly = analogRead(Pot)/4;<br /> delay(dly);<br /> break;<br /><br /> case 5:<br /> digitalWrite(ST_X1, LOW);<br /> digitalWrite(ST_X2, LOW);<br /> digitalWrite(ST_Y1, HIGH);<br /> digitalWrite(ST_Y2, HIGH);<br /> dly = analogRead(Pot)/4;<br /> delay(dly);<br /> break;<br /><br /> case 6:<br /> digitalWrite(ST_X1, LOW);<br /> digitalWrite(ST_X2, LOW);<br /> digitalWrite(ST_Y1, LOW);<br /> digitalWrite(ST_Y2, HIGH);<br /> dly = analogRead(Pot)/4;<br /> delay(dly);<br /> break;<br /><br /> case 7:<br /> digitalWrite(ST_X1, HIGH);<br /> digitalWrite(ST_X2, LOW);<br /> digitalWrite(ST_Y1, LOW);<br /> digitalWrite(ST_Y2, HIGH);<br /> dly = analogRead(Pot)/4;<br /> delay(dly);<br /> break;<br /> }<br />}<br /> <br />void StopMotor(){<br /> digitalWrite(ST_X1, LOW);<br /> digitalWrite(ST_X2, LOW);<br /> digitalWrite(ST_Y1, LOW);<br /> digitalWrite(ST_Y2, LOW);<br />}久世http://www.blogger.com/profile/06898487025751982552[email protected]0tag:blogger.com,1999:blog-6697050553453132238.post-90312661953785816832009-06-02T12:26:00.003+09:002009-06-29T12:52:49.936+09:00実用的なステッピングモーターのプログラム その2スイッチを押している間、逆回転します。<br /><br /><a href="http://www.kuze.jp/geikoudai/jikken2009spring/page07.html">こちらで解説</a><br /><br />---<br /><br />//StepMotor sample<br />//2009.6.2<br /> <br />//PinAssign<br />int ST_X1=2;<br />int ST_X2=4;<br />int ST_Y1=3;<br />int ST_Y2=5;<br />int ledPin=13;<br /> <br />//PotentionMeter<br />int Pot=5;<br />//Switch<br />int Switch=6;<br />int dly;<br />signed int Count=0;<br />signed int Dimmention=1;<br /><br /> <br />void setup(){<br /> pinMode(ST_X1, OUTPUT);<br /> pinMode(ST_X2, OUTPUT);<br /> pinMode(ST_Y1, OUTPUT);<br /> pinMode(ST_Y2, OUTPUT);<br /> pinMode(ledPin, OUTPUT);<br /> //POT is Default AnalogInput<br /> pinMode(Switch,INPUT);<br /> dly = analogRead(Pot)/4;<br />}<br /> <br />void MoveMotor(int stp){<br /> int s;<br /> s=stp%8;<br /><br /> switch(s){<br /> case 0:<br /> digitalWrite(ST_X1, HIGH);<br /> digitalWrite(ST_X2, LOW);<br /> digitalWrite(ST_Y1, LOW);<br /> digitalWrite(ST_Y2, LOW);<br /> dly = analogRead(Pot)/4;<br /> delay(dly);<br /> break;<br /><br /> case 1:<br /> digitalWrite(ST_X1, HIGH);<br /> digitalWrite(ST_X2, HIGH);<br /> digitalWrite(ST_Y1, LOW);<br /> digitalWrite(ST_Y2, LOW);<br /> dly = analogRead(Pot)/4;<br /> delay(dly);<br /> break;<br /><br /> case 2:<br /> digitalWrite(ST_X1, LOW);<br /> digitalWrite(ST_X2, HIGH);<br /> digitalWrite(ST_Y1, LOW);<br /> digitalWrite(ST_Y2, LOW);<br /> dly = analogRead(Pot)/4;<br /> delay(dly);<br /> break;<br /><br /> case 3:<br /> digitalWrite(ST_X1, LOW);<br /> digitalWrite(ST_X2, HIGH);<br /> digitalWrite(ST_Y1, HIGH);<br /> digitalWrite(ST_Y2, LOW);<br /> dly = analogRead(Pot)/4;<br /> delay(dly);<br /> break;<br /><br /> case 4:<br /> digitalWrite(ST_X1, LOW);<br /> digitalWrite(ST_X2, LOW);<br /> digitalWrite(ST_Y1, HIGH);<br /> digitalWrite(ST_Y2, LOW);<br /> dly = analogRead(Pot)/4;<br /> delay(dly);<br /> break;<br /><br /> case 5:<br /> digitalWrite(ST_X1, LOW);<br /> digitalWrite(ST_X2, LOW);<br /> digitalWrite(ST_Y1, HIGH);<br /> digitalWrite(ST_Y2, HIGH);<br /> dly = analogRead(Pot)/4;<br /> delay(dly);<br /> break;<br /><br /> case 6:<br /> digitalWrite(ST_X1, LOW);<br /> digitalWrite(ST_X2, LOW);<br /> digitalWrite(ST_Y1, LOW);<br /> digitalWrite(ST_Y2, HIGH);<br /> dly = analogRead(Pot)/4;<br /> delay(dly);<br /> break;<br /><br /> case 7:<br /> digitalWrite(ST_X1, HIGH);<br /> digitalWrite(ST_X2, LOW);<br /> digitalWrite(ST_Y1, LOW);<br /> digitalWrite(ST_Y2, HIGH);<br /> dly = analogRead(Pot)/4;<br /> delay(dly);<br /> break;<br /> }<br />}<br /> <br />void StopMotor(){<br /> digitalWrite(ST_X1, LOW);<br /> digitalWrite(ST_X2, LOW);<br /> digitalWrite(ST_Y1, LOW);<br /> digitalWrite(ST_Y2, LOW);<br />}<br /> <br />void loop(){<br /> if(digitalRead(Switch)==1){<br /> Dimmention=1;<br /> }else{<br /> Dimmention=-1;<br /> }<br /> <br /> Count=Count+Dimmention;<br /> <br /> if(Count>96){<br /> Count=0;<br /> }else if(Count<0){<br /> Count=96;<br /> }<br /> <br /> MoveMotor(Count);<br /> <br />}久世http://www.blogger.com/profile/06898487025751982552[email protected]1tag:blogger.com,1999:blog-6697050553453132238.post-16897436725758832222009-06-02T12:03:00.005+09:002009-06-29T12:53:00.126+09:00実用的なステッピングモーターのプログラム その1モーターの回転を、指定したステップ数で行うプログラムです。<br /><a href="http://www.kuze.jp/geikoudai/jikken2009spring/page06.html">こちらに解説</a><br /><br />----<br />//StepMotor sample<br />//<br /><br />//PinAssign<br />int ST_X1=2;<br />int ST_X2=4;<br />int ST_Y1=3;<br />int ST_Y2=5;<br />int ledPin=13;<br /><br />//PotentionMeter<br />int Pot=5;<br />//Switch<br />int Switch=6;<br /><br />int dly;<br />int Count=0;<br /><br />void setup(){<br /> pinMode(ST_X1, OUTPUT);<br /> pinMode(ST_X2, OUTPUT);<br /> pinMode(ST_Y1, OUTPUT);<br /> pinMode(ST_Y2, OUTPUT);<br /> pinMode(ledPin, OUTPUT);<br /><br /> //POT is Default AnalogInput<br /> pinMode(Switch,INPUT);<br /> dly = analogRead(Pot)/4;<br />}<br /><br />void MoveMotor(int stp){<br /> int s;<br /> s=stp%8;<br /> <br /> switch(s){<br /> case 0:<br /> digitalWrite(ST_X1, HIGH);<br /> digitalWrite(ST_X2, LOW);<br /> digitalWrite(ST_Y1, LOW);<br /> digitalWrite(ST_Y2, LOW);<br /> dly = analogRead(Pot)/4;<br /> delay(dly);<br /> break;<br /> <br /> case 1:<br /> digitalWrite(ST_X1, HIGH);<br /> digitalWrite(ST_X2, HIGH);<br /> digitalWrite(ST_Y1, LOW);<br /> digitalWrite(ST_Y2, LOW);<br /> dly = analogRead(Pot)/4;<br /> delay(dly);<br /> break;<br /> <br /> case 2:<br /> digitalWrite(ST_X1, LOW);<br /> digitalWrite(ST_X2, HIGH);<br /> digitalWrite(ST_Y1, LOW);<br /> digitalWrite(ST_Y2, LOW);<br /> dly = analogRead(Pot)/4;<br /> delay(dly);<br /> break;<br /> <br /> case 3:<br /> digitalWrite(ST_X1, LOW);<br /> digitalWrite(ST_X2, HIGH);<br /> digitalWrite(ST_Y1, HIGH);<br /> digitalWrite(ST_Y2, LOW);<br /> dly = analogRead(Pot)/4;<br /> delay(dly);<br /> break;<br /> <br /> case 4:<br /> digitalWrite(ST_X1, LOW);<br /> digitalWrite(ST_X2, LOW);<br /> digitalWrite(ST_Y1, HIGH);<br /> digitalWrite(ST_Y2, LOW);<br /> dly = analogRead(Pot)/4;<br /> delay(dly);<br /> break;<br /> <br /> case 5:<br /> digitalWrite(ST_X1, LOW);<br /> digitalWrite(ST_X2, LOW);<br /> digitalWrite(ST_Y1, HIGH);<br /> digitalWrite(ST_Y2, HIGH);<br /> dly = analogRead(Pot)/4;<br /> delay(dly);<br /> break;<br /> <br /> case 6:<br /> digitalWrite(ST_X1, LOW);<br /> digitalWrite(ST_X2, LOW);<br /> digitalWrite(ST_Y1, LOW);<br /> digitalWrite(ST_Y2, HIGH);<br /> dly = analogRead(Pot)/4;<br /> delay(dly);<br /> break;<br /> <br /> case 7:<br /> digitalWrite(ST_X1, HIGH);<br /> digitalWrite(ST_X2, LOW);<br /> digitalWrite(ST_Y1, LOW);<br /> digitalWrite(ST_Y2, HIGH);<br /> dly = analogRead(Pot)/4;<br /> delay(dly);<br /> break;<br /> }<br />}<br /><br />void StopMotor(){<br /> digitalWrite(ST_X1, LOW);<br /> digitalWrite(ST_X2, LOW);<br /> digitalWrite(ST_Y1, LOW);<br /> digitalWrite(ST_Y2, LOW);<br />}<br /><br /><br />void loop(){<br /><br /> if(digitalRead(Switch)==1){<br /> Count=Count+1;<br /> MoveMotor(Count);<br /> <br /> }<br /> else{<br /> StopMotor();<br /> }<br />}久世http://www.blogger.com/profile/06898487025751982552[email protected]0tag:blogger.com,1999:blog-6697050553453132238.post-59726919676036523822009-06-02T11:52:00.004+09:002009-06-29T12:53:09.776+09:00ステッピングモーターの回転についていままで、ステッピングモーターを回すのに、モーターの中の4つの電磁石をArduinoの4つのピンをつかって切り替えてきました。<br />厳密にいうと違いますが(2相の磁石を切り替えてるので個数が4つじゃない)、こんな感じでイメージしておいていいと思います。<br /><br />さて、今までは、4つの電磁石のうち1つだけを磁石にして、回転させてきましたが、これだといろいろ問題が出てきてしまうので、実用的に使われてはいません。<br /><br />どんな問題かというと、、<br /><br />バケツリレーを思い浮かべてください。<br />隣の人に、水のたっぷり入ったバケツを渡すとき、自分と隣の人の2人が一瞬だけバケツを持ち合うことで、水をこぼすことなく、スムーズにリレーできます。<br /><br />これが、自分と隣の人が完全に分かれて、バケツを持つのは1人だけにしてしまうと、どうなるでしょうか。<br />おそらく、バケツリレーは成り立つと思いますが、バケツを落としたり、重さが全部自分にかかるので、やたら疲れてしまいます。<br /><br />ステッピングモーターの中でもこんなことが起きてます。<br /><br />なので、通常は、2つの電磁石をオンにする瞬間も必要になります。<br /><br /><a href="http://homepage1.nifty.com/rikiya/software/114stepping1.htm">参考サイト</a><br /><br /><br />▼今までのプログラム(抜粋)<br />-----<br /> digitalWrite(ST_X1, HIGH);<br /> digitalWrite(ST_X2, LOW);<br /> digitalWrite(ST_Y1, LOW);<br /> digitalWrite(ST_Y2, LOW);<br /> <br /> delay(25);<br /><br /> digitalWrite(ST_X1, LOW);<br /> digitalWrite(ST_X2, HIGH);<br /> digitalWrite(ST_Y1, LOW);<br /> digitalWrite(ST_Y2, LOW);<br /> <br /> delay(25);<br /> <br /> digitalWrite(ST_X1, LOW);<br /> digitalWrite(ST_X2, LOW);<br /> digitalWrite(ST_Y1, HIGH);<br /> digitalWrite(ST_Y2, LOW);<br /> <br /> delay(25);<br /><br /> digitalWrite(ST_X1, LOW);<br /> digitalWrite(ST_X2, LOW);<br /> digitalWrite(ST_Y1, LOW);<br /> digitalWrite(ST_Y2, HIGH);<br /> <br /> delay(25);<br />----<br /><br />▼改良したプログラム(抜粋)<br />----<br /> digitalWrite(ST_X1, HIGH);<br /> digitalWrite(ST_X2, LOW);<br /> digitalWrite(ST_Y1, LOW);<br /> digitalWrite(ST_Y2, LOW);<br /><br /> delay(25);<br /><br /> digitalWrite(ST_X1, HIGH);<br /> digitalWrite(ST_X2, HIGH);<br /> digitalWrite(ST_Y1, LOW);<br /> digitalWrite(ST_Y2, LOW);<br /><br /> delay(25);<br /><br /> digitalWrite(ST_X1, LOW);<br /> digitalWrite(ST_X2, HIGH);<br /> digitalWrite(ST_Y1, LOW);<br /> digitalWrite(ST_Y2, LOW);<br /><br /> delay(25);<br /><br /> digitalWrite(ST_X1, LOW);<br /> digitalWrite(ST_X2, HIGH);<br /> digitalWrite(ST_Y1, HIGH);<br /> digitalWrite(ST_Y2, LOW);<br /><br /> delay(25);<br /><br /> digitalWrite(ST_X1, LOW);<br /> digitalWrite(ST_X2, LOW);<br /> digitalWrite(ST_Y1, HIGH);<br /> digitalWrite(ST_Y2, LOW);<br /><br /> delay(25);<br /><br /> digitalWrite(ST_X1, LOW);<br /> digitalWrite(ST_X2, LOW);<br /> digitalWrite(ST_Y1, HIGH);<br /> digitalWrite(ST_Y2, HIGH);<br /><br /> delay(25);<br /><br /> digitalWrite(ST_X1, LOW);<br /> digitalWrite(ST_X2, LOW);<br /> digitalWrite(ST_Y1, LOW);<br /> digitalWrite(ST_Y2, HIGH);<br /><br /> delay(25);<br /><br /> digitalWrite(ST_X1, HIGH);<br /> digitalWrite(ST_X2, LOW);<br /> digitalWrite(ST_Y1, LOW);<br /> digitalWrite(ST_Y2, HIGH);<br /><br /> delay(25);<br />----久世http://www.blogger.com/profile/06898487025751982552[email protected]0tag:blogger.com,1999:blog-6697050553453132238.post-17589221044843254482009-05-26T11:28:00.002+09:002009-06-29T12:58:27.475+09:00ステッピングモーターのプログラム(3)<div>スイッチを押している間、回転するバージョン</div><div><br /></div><div>-----</div><div><br /></div><div>//StepMotor sample</div><div><br /></div><div>//PinAssign</div><div>int ST_X1=2;</div><div>int ST_X2=4;</div><div>int ST_Y1=3;</div><div>int ST_Y2=5;</div><div>int ledPin=13;</div><div><br /></div><div>//PotentionMeter</div><div>int Pot=5;</div><div>//Switch</div><div>int Switch=6;</div><div><br /></div><div>int dly;</div><div><br /></div><div>void setup(){</div><div> pinMode(ST_X1, OUTPUT);</div><div> pinMode(ST_X2, OUTPUT);</div><div> pinMode(ST_Y1, OUTPUT);</div><div> pinMode(ST_Y2, OUTPUT);</div><div> pinMode(ledPin, OUTPUT);</div><div><br /></div><div> //POT is Default AnalogInput</div><div> pinMode(Switch,INPUT);</div><div> dly = analogRead(Pot)/4;</div><div>}</div><div><br /></div><div>void loop(){</div><div><br /></div><div> if(digitalRead(Switch)==1){</div><div><br /></div><div><br /></div><div> digitalWrite(ledPin,HIGH);</div><div><br /></div><div> digitalWrite(ST_X1, HIGH);</div><div> digitalWrite(ST_X2, LOW);</div><div> digitalWrite(ST_Y1, LOW);</div><div> digitalWrite(ST_Y2, LOW);</div><div><br /></div><div><br /></div><div> dly = analogRead(Pot)/4;</div><div> delay(dly);</div><div><br /></div><div> digitalWrite(ST_X1, HIGH);</div><div> digitalWrite(ST_X2, HIGH);</div><div> digitalWrite(ST_Y1, LOW);</div><div> digitalWrite(ST_Y2, LOW);</div><div><br /></div><div><br /></div><div> dly = analogRead(Pot)/4;</div><div> delay(dly);</div><div><br /></div><div> digitalWrite(ST_X1, LOW);</div><div> digitalWrite(ST_X2, HIGH);</div><div> digitalWrite(ST_Y1, LOW);</div><div> digitalWrite(ST_Y2, LOW);</div><div><br /></div><div><br /></div><div> dly = analogRead(Pot)/4;</div><div> delay(dly);</div><div><br /></div><div> digitalWrite(ledPin,LOW);</div><div><br /></div><div> digitalWrite(ST_X1, LOW);</div><div> digitalWrite(ST_X2, HIGH);</div><div> digitalWrite(ST_Y1, HIGH);</div><div> digitalWrite(ST_Y2, LOW);</div><div><br /></div><div><br /></div><div> dly = analogRead(Pot)/4;</div><div> delay(dly);</div><div><br /></div><div> digitalWrite(ST_X1, LOW);</div><div> digitalWrite(ST_X2, LOW);</div><div> digitalWrite(ST_Y1, HIGH);</div><div> digitalWrite(ST_Y2, LOW);</div><div><br /></div><div><br /></div><div> dly = analogRead(Pot)/4;</div><div> delay(dly);</div><div><br /></div><div> digitalWrite(ST_X1, LOW);</div><div> digitalWrite(ST_X2, LOW);</div><div> digitalWrite(ST_Y1, HIGH);</div><div> digitalWrite(ST_Y2, HIGH);</div><div><br /></div><div><br /></div><div> dly = analogRead(Pot)/4;</div><div> delay(dly);</div><div><br /></div><div> digitalWrite(ST_X1, LOW);</div><div> digitalWrite(ST_X2, LOW);</div><div> digitalWrite(ST_Y1, LOW);</div><div> digitalWrite(ST_Y2, HIGH);</div><div><br /></div><div><br /></div><div> dly = analogRead(Pot)/4;</div><div> delay(dly);</div><div><br /></div><div> digitalWrite(ST_X1, HIGH);</div><div> digitalWrite(ST_X2, LOW);</div><div> digitalWrite(ST_Y1, LOW);</div><div> digitalWrite(ST_Y2, HIGH);</div><div><br /></div><div><br /></div><div> dly = analogRead(Pot)/4;</div><div> delay(dly);</div><div><br /></div><div> }</div><div> else{</div><div> digitalWrite(ST_X1, LOW);</div><div> digitalWrite(ST_X2, LOW);</div><div> digitalWrite(ST_Y1, LOW);</div><div> digitalWrite(ST_Y2, LOW);</div><div> }</div><div>}</div><div><br /></div><div><br /></div>久世http://www.blogger.com/profile/06898487025751982552[email protected]0tag:blogger.com,1999:blog-6697050553453132238.post-86299061345310789732009-05-26T11:22:00.003+09:002009-06-29T12:58:38.548+09:00ステッピングモーターのプログラム(2)<div><div>モーターのスピードを簡単に変更できるバージョン</div><div>「dly」という変数で一括してスピードコントロールできます。</div><div>-----</div><div><br /></div><div>//StepMotor sample</div><div><br /></div><div>//Pin Assgin</div><div>int ST_X1=2;</div><div>int ST_X2=4;</div><div>int ST_Y1=3;</div><div>int ST_Y2=5;</div><div>int ledPin=13;</div><div><br /></div><div>//DelayTime</div><div>int dly=2;</div><div><br /></div><div><br /></div><div>void setup(){</div><div> pinMode(ST_X1, OUTPUT);</div><div> pinMode(ST_X2, OUTPUT);</div><div> pinMode(ST_Y1, OUTPUT);</div><div> pinMode(ST_Y2, OUTPUT);</div><div> pinMode(ledPin, OUTPUT);</div><div> </div><div>}</div><div><br /></div><div>void loop(){</div><div> digitalWrite(ledPin,HIGH);</div><div> </div><div> digitalWrite(ST_X1, HIGH);</div><div> digitalWrite(ST_X2, LOW);</div><div> digitalWrite(ST_Y1, LOW);</div><div> digitalWrite(ST_Y2, LOW);</div><div> </div><div> delay(dly);</div><div><br /></div><div> digitalWrite(ST_X1, HIGH);</div><div> digitalWrite(ST_X2, HIGH);</div><div> digitalWrite(ST_Y1, LOW);</div><div> digitalWrite(ST_Y2, LOW);</div><div> </div><div> delay(dly);</div><div><br /></div><div> digitalWrite(ST_X1, LOW);</div><div> digitalWrite(ST_X2, HIGH);</div><div> digitalWrite(ST_Y1, LOW);</div><div> digitalWrite(ST_Y2, LOW);</div><div> </div><div> delay(dly);</div><div><br /></div><div> digitalWrite(ledPin,LOW);</div><div> </div><div> digitalWrite(ST_X1, LOW);</div><div> digitalWrite(ST_X2, HIGH);</div><div> digitalWrite(ST_Y1, HIGH);</div><div> digitalWrite(ST_Y2, LOW);</div><div> </div><div> delay(dly);</div><div><br /></div><div> digitalWrite(ST_X1, LOW);</div><div> digitalWrite(ST_X2, LOW);</div><div> digitalWrite(ST_Y1, HIGH);</div><div> digitalWrite(ST_Y2, LOW);</div><div> </div><div> delay(dly);</div><div><br /></div><div> digitalWrite(ST_X1, LOW);</div><div> digitalWrite(ST_X2, LOW);</div><div> digitalWrite(ST_Y1, HIGH);</div><div> digitalWrite(ST_Y2, HIGH);</div><div> </div><div> delay(dly);</div><div> </div><div> digitalWrite(ST_X1, LOW);</div><div> digitalWrite(ST_X2, LOW);</div><div> digitalWrite(ST_Y1, LOW);</div><div> digitalWrite(ST_Y2, HIGH);</div><div> </div><div> delay(dly);</div><div><br /></div><div> digitalWrite(ST_X1, HIGH);</div><div> digitalWrite(ST_X2, LOW);</div><div> digitalWrite(ST_Y1, LOW);</div><div> digitalWrite(ST_Y2, HIGH);</div><div> </div><div> delay(dly);</div><div> </div><div>}</div><div><br /></div><div><br /></div></div>久世http://www.blogger.com/profile/06898487025751982552[email protected]0tag:blogger.com,1999:blog-6697050553453132238.post-59606366557214663482009-05-25T22:50:00.005+09:002009-06-29T12:58:52.993+09:00ステッピングモーターのプログラム(1)まず、モーターをつないで動作確認をするので、以下のプログラムを書いてください。<div>今回使うモーターは「ステッピングモーター」というモーターで、4つのコイルが90度ずつの一に入っていて、1つ1つを時間差で電磁石にすることで、軸についた永久磁石が反発を起こしてクルっと回ります。リニアモーターカーみたいな原理。「水に沈む前に次の足を出す」ような感じ。<br /></div><div><br /></div><div><br /></div><div>---</div><div><div>//StepMotor sample</div><div><br /></div><div>//Pin Assign</div><div>int ST_X1=2;</div><div>int ST_X2=4;</div><div>int ST_Y1=3;</div><div>int ST_Y2=5;</div><div>int ledPin=13;</div><div><br /></div><div><br /></div><div>void setup(){</div><div> pinMode(ST_X1, OUTPUT);</div><div> pinMode(ST_X2, OUTPUT);</div><div> pinMode(ST_Y1, OUTPUT);</div><div> pinMode(ST_Y2, OUTPUT);</div><div> pinMode(ledPin, OUTPUT);</div><div> </div><div>}</div><div><br /></div><div>void loop(){</div><div> digitalWrite(ledPin,HIGH);</div><div> </div><div> digitalWrite(ST_X1, HIGH);</div><div> digitalWrite(ST_X2, LOW);</div><div> digitalWrite(ST_Y1, LOW);</div><div> digitalWrite(ST_Y2, LOW);</div><div> </div><div> delay(25);</div><div><br /></div><div> digitalWrite(ST_X1, LOW);</div><div> digitalWrite(ST_X2, HIGH);</div><div> digitalWrite(ST_Y1, LOW);</div><div> digitalWrite(ST_Y2, LOW);</div><div> </div><div> delay(25);</div><div><br /></div><div> digitalWrite(ledPin,LOW);</div><div> </div><div> digitalWrite(ST_X1, LOW);</div><div> digitalWrite(ST_X2, LOW);</div><div> digitalWrite(ST_Y1, HIGH);</div><div> digitalWrite(ST_Y2, LOW);</div><div> </div><div> delay(25);</div><div><br /></div><div> digitalWrite(ST_X1, LOW);</div><div> digitalWrite(ST_X2, LOW);</div><div> digitalWrite(ST_Y1, LOW);</div><div> digitalWrite(ST_Y2, HIGH);</div><div> </div><div> delay(25);</div><div><br /></div><div> </div><div> </div><div>}</div><div><br /></div><div><br /></div></div><div><br /></div><div><br /></div><div><br /></div>久世http://www.blogger.com/profile/06898487025751982552[email protected]0