Changes between Version 9 and Version 10 of BD62xx-Basic


Ignore:
Timestamp:
Apr 11, 2009 9:56:37 PM (12 years ago)
Author:
sgk
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • BD62xx-Basic

    v9 v10  
    7272|| 論理1 || 論理1 || ブレーキ ||
    7373
     74== スケッチの例 ==
     75
     76{{{
     77#!c
     78int FIN = 5;
     79int RIN = 6;
     80int OFFSET = 1.0 * 256 / 5;
     81int MAX = 1.5 * 256 / 5 - OFFSET;
     82int degree = 0;
     83
     84void setup() {
     85  Serial.begin(9600);
     86  pinMode(FIN, OUTPUT);
     87  pinMode(RIN, OUTPUT);
     88}
     89
     90void loop() {
     91  delay(100);
     92  degree += 1;
     93  degree %= 360;
     94  long v = int(sin(degree * 2 * PI / 360) * MAX);
     95  Serial.println(v);
     96  if (v > 0) {
     97    analogWrite(FIN, v + OFFSET);
     98    analogWrite(RIN, 0);
     99  } else
     100  if (v < 0) {
     101    analogWrite(FIN, 0);
     102    analogWrite(RIN, OFFSET - v);
     103  } else {
     104    Serial.println();
     105    analogWrite(FIN, 255);
     106    analogWrite(RIN, 255);
     107  }
     108}
     109}}}
     110
    74111''(2009/4/10 - sgk)''