2017年5月5日金曜日
2017年5月4日木曜日
いやいや
const int deg0msec = 600; // msec.
const int deg180msec = 2350; // msec.
int microSec = deg0msec;
void setup() {
pinMode( 2, OUTPUT );
pinMode(4,INPUT) ;
Serial.begin( 9600 );
}
void loop() {
int i;
if (digitalRead(4) == LOW) {
for(i=0;i<2;i++){
microSec = deg0msec + 80 / 180.0 * ( deg180msec - deg0msec );
if ( microSec >= deg0msec ) {
digitalWrite( 2, HIGH );
delayMicroseconds( microSec ); // ON
digitalWrite( 2, LOW );
delayMicroseconds( 10000 ); // OFF
delayMicroseconds( 10000 - microSec ); // OFF40
}
delay(500);
microSec = deg0msec + 0 / 180.0 * ( deg180msec - deg0msec );
if ( microSec >= deg0msec ) {
digitalWrite( 2, HIGH );
delayMicroseconds( microSec ); // ON
digitalWrite( 2, LOW );
delayMicroseconds( 10000 ); // OFF
delayMicroseconds( 10000 - microSec ); // OFF40
}
delay(500);
}
}
if (digitalRead(4) == HIGH) {
microSec = deg0msec + 30 / 180.0 * ( deg180msec - deg0msec );
if ( microSec >= deg0msec ) {
digitalWrite( 2, HIGH );
delayMicroseconds( microSec ); // ON
digitalWrite( 2, LOW );
delayMicroseconds( 10000 ); // OFF
delayMicroseconds( 10000 - microSec ); // OFF40
}
}
}
int serialReadAsInt() {
char c[ 9 ] = "0";
for ( int i = 0; i < 8; i++ ) {
c[ i ] = Serial.read();
if ( c[ i ] == '\0' )
break;
}
return atoi( c );
}
驚いて口を開く
const int deg0msec = 600; // msec.
const int deg180msec = 2350; // msec.
int microSec = deg0msec;
int cnt = 0;
void setup() {
pinMode( 4, OUTPUT );
pinMode(2,INPUT) ;
Serial.begin( 9600 );
}
void loop() {
if ( Serial.available() > 0 ) {
delay(10);
int deg = serialReadAsInt();
if ( deg >= 0 && deg <= 180 )
microSec = deg0msec + deg / 180.0 * ( deg180msec - deg0msec );
}
if (digitalRead(2) == LOW) {
microSec = deg0msec + 45 / 180.0 * ( deg180msec - deg0msec );
Serial.print("BIN");
}
if (digitalRead(2) == HIGH) {
microSec = deg0msec + 0 / 180.0 * ( deg180msec - deg0msec );
}
// create PWM
if ( microSec >= deg0msec ) {
digitalWrite( 4, HIGH );
delayMicroseconds( microSec ); // ON
//digitalWrite( 4, HIGH );
digitalWrite( 4, LOW );
delayMicroseconds( 10000 ); // OFF
delayMicroseconds( 10000 - microSec ); // OFF
}
}
int serialReadAsInt() {
char c[ 9 ] = "0";
for ( int i = 0; i < 8; i++ ) {
c[ i ] = Serial.read();
if ( c[ i ] == '\0' )
break;
}
return atoi( c );
}
2017年5月3日水曜日
驚いて落ち着く
//ライブラリをインクルード
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 6 //Arduinoで使うピン
#define NUMPIXELS 1 //LEDの数。
int cnt = 0;
uint8_t LedNum1_Inc = 0;
uint8_t ChangeType = 0;
uint32_t ChangeTime;
int flag = 0;
int r = 255;
int g = 100;
int b = 80;
//ライブラリのセットアップ
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
pixels.begin(); // ライブラリ使用開始
pixels.setBrightness(255);
ChangeTime = millis();
pinMode(2,INPUT) ;
Serial.begin(9600);
}
//ただ白っぽく光らせるだけ
void loop() {
int val=0;
if(millis() - ChangeTime > 10){ //15 second Type Change
if (digitalRead(2) == LOW) {
cnt = 0;
r++;
g--;
b--;
if(r>255)r=255;
if(g<0)g=0;
if(b<0)b=0;
}
if (digitalRead(2) == HIGH) {
g++;
b++;
if(g>100)g=100;
if(b>80)b=80;
if (g == 100 && b == 80){
cnt++;
}
if(cnt > 1000){
r--;
b++;
if(r < 100)r =100;
if(b > 255)b=255;
Serial.print("BIN");
}
}
ChangeTime = millis();
pixels.setPixelColor(LedNum1_Inc, pixels.Color(g, r, b));
pixels.show(); // This sends the updated pixel color to the hardware.
}
}
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 6 //Arduinoで使うピン
#define NUMPIXELS 1 //LEDの数。
int cnt = 0;
uint8_t LedNum1_Inc = 0;
uint8_t ChangeType = 0;
uint32_t ChangeTime;
int flag = 0;
int r = 255;
int g = 100;
int b = 80;
//ライブラリのセットアップ
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
pixels.begin(); // ライブラリ使用開始
pixels.setBrightness(255);
ChangeTime = millis();
pinMode(2,INPUT) ;
Serial.begin(9600);
}
//ただ白っぽく光らせるだけ
void loop() {
int val=0;
if(millis() - ChangeTime > 10){ //15 second Type Change
if (digitalRead(2) == LOW) {
cnt = 0;
r++;
g--;
b--;
if(r>255)r=255;
if(g<0)g=0;
if(b<0)b=0;
}
if (digitalRead(2) == HIGH) {
g++;
b++;
if(g>100)g=100;
if(b>80)b=80;
if (g == 100 && b == 80){
cnt++;
}
if(cnt > 1000){
r--;
b++;
if(r < 100)r =100;
if(b > 255)b=255;
Serial.print("BIN");
}
}
ChangeTime = millis();
pixels.setPixelColor(LedNum1_Inc, pixels.Color(g, r, b));
pixels.show(); // This sends the updated pixel color to the hardware.
}
}
グラデーション
//ライブラリをインクルード
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 6 //Arduinoで使うピン
#define NUMPIXELS 1 //LEDの数。
int cnt = 0;
uint8_t LedNum1_Inc = 0;
uint8_t ChangeType = 0;
uint32_t ChangeTime;
//ライブラリのセットアップ
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
pixels.begin(); // ライブラリ使用開始
pixels.setBrightness(255);
ChangeTime = millis();
}
//ただ白っぽく光らせるだけ
void loop() {
int val=0;
if(millis() - ChangeTime > 10){ //15 second Type Change
cnt++;
if(cnt == 255 * 6)cnt = 0;
ChangeType = (int)(cnt / 255);
val = cnt % 255;
ChangeTime = millis();
switch(ChangeType){
case 0:
pixels.setPixelColor(LedNum1_Inc, pixels.Color(255, val, 0));
pixels.show(); // This sends the updated pixel color to the hardware.
break;
case 1:
pixels.setPixelColor(LedNum1_Inc, pixels.Color(255-val, 255, 0));
pixels.show();
break;
case 2:
pixels.setPixelColor(LedNum1_Inc, pixels.Color(0, 255, val));
pixels.show();
break;
case 3:
pixels.setPixelColor(LedNum1_Inc, pixels.Color(0, 255-val, 255));
pixels.show();
break;
case 4:
pixels.setPixelColor(LedNum1_Inc, pixels.Color(val, 0, 255));
pixels.show();
break;
case 5:
pixels.setPixelColor(LedNum1_Inc, pixels.Color(255, 0, 255-val));
pixels.show();
break;
}
}
}
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 6 //Arduinoで使うピン
#define NUMPIXELS 1 //LEDの数。
int cnt = 0;
uint8_t LedNum1_Inc = 0;
uint8_t ChangeType = 0;
uint32_t ChangeTime;
//ライブラリのセットアップ
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
pixels.begin(); // ライブラリ使用開始
pixels.setBrightness(255);
ChangeTime = millis();
}
//ただ白っぽく光らせるだけ
void loop() {
int val=0;
if(millis() - ChangeTime > 10){ //15 second Type Change
cnt++;
if(cnt == 255 * 6)cnt = 0;
ChangeType = (int)(cnt / 255);
val = cnt % 255;
ChangeTime = millis();
switch(ChangeType){
case 0:
pixels.setPixelColor(LedNum1_Inc, pixels.Color(255, val, 0));
pixels.show(); // This sends the updated pixel color to the hardware.
break;
case 1:
pixels.setPixelColor(LedNum1_Inc, pixels.Color(255-val, 255, 0));
pixels.show();
break;
case 2:
pixels.setPixelColor(LedNum1_Inc, pixels.Color(0, 255, val));
pixels.show();
break;
case 3:
pixels.setPixelColor(LedNum1_Inc, pixels.Color(0, 255-val, 255));
pixels.show();
break;
case 4:
pixels.setPixelColor(LedNum1_Inc, pixels.Color(val, 0, 255));
pixels.show();
break;
case 5:
pixels.setPixelColor(LedNum1_Inc, pixels.Color(255, 0, 255-val));
pixels.show();
break;
}
}
}
登録:
投稿 (Atom)