User:Zalán Szakács/grad prototyping: Difference between revisions
No edit summary |
No edit summary |
||
Line 147: | Line 147: | ||
</gallery> | </gallery> | ||
<br> | <br> | ||
'''4. Arduino Script''' | |||
<pre> | |||
// NeoPixel Ring simple sketch (c) 2013 Shae Erisson | |||
// released under the GPLv3 license to match the rest of the AdaFruit NeoPixel library | |||
#include <Adafruit_NeoPixel.h> | |||
#ifdef __AVR__ | |||
#include <avr/power.h> | |||
#endif | |||
// Which pin on the Arduino is connected to the NeoPixels? | |||
// On a Trinket or Gemma we suggest changing this to 1 | |||
#define PIN 6 | |||
// How many NeoPixels are attached to the Arduino? | |||
#define NUMPIXELS 16 | |||
// When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals. | |||
// Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest | |||
// example for more information on possible values. | |||
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); | |||
int delayval = 500; // delay for half a second | |||
void setup() { | |||
// This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket | |||
#if defined (__AVR_ATtiny85__) | |||
if (F_CPU == 16000000) clock_prescale_set(clock_div_1); | |||
#endif | |||
// End of trinket special code | |||
pixels.begin(); // This initializes the NeoPixel library. | |||
} | |||
void loop() { | |||
// For a set of NeoPixels the first NeoPixel is 0, second is 1, all the way up to the count of pixels minus one. | |||
for(int i=0;i<NUMPIXELS;i++){ | |||
// pixels.Color takes RGB values, from 0,0,0 up to 255,255,255 | |||
pixels.setPixelColor(i, pixels.Color(0,150,0)); // Moderately bright green color. | |||
pixels.show(); // This sends the updated pixel color to the hardware. | |||
delay(delayval); // Delay for a period of time (in milliseconds). | |||
} | |||
} | |||
</pre> |
Revision as of 09:14, 4 October 2018
P R O T O T Y P I N G
What is a Circuit?
What are Resistors?
conversion calculator resistor color code
Light-Emitting Diodes (LEDs)
How to use Arduino?
1. Arduino Script
* * Zalan's first Program */ int ledPin = 13; void setup() { //initialize pins as outputs pinMode(ledPin, OUTPUT); } void loop() { digitalWrite(ledPin, HIGH); delay(1000); digitalWrite(ledPin, LOW); delay(1000); }
2. Arduino Script
int LED = 12; int BUTTON = 4; void setup() { pinMode(LED,OUTPUT); pinMode(BUTTON,INPUT); } void loop() { if(digitalRead(BUTTON) == HIGH) { digitalWrite(LED,HIGH); }else { digitalWrite(LED,LOW); } }
3. Arduino Script
int switchPin = 8; int ledPin = 13; boolean lastButton = LOW; boolean currentButton = LOW; boolean ledOn = false; void setup() { pinMode(switchPin, INPUT); pinMode(ledPin, OUTPUT); } boolean debounce(boolean last) { boolean current = digitalRead(switchPin); if (last != current) { delay(5); current = digitalRead(switchPin); } return current; } void loop() { currentButton = debounce(lastButton); if (lastButton == LOW && currentButton == HIGH) { ledOn -= !ledOn; } lastButton = currentButton; digitalWrite(ledPin, ledOn); }
4. Arduino Script
// NeoPixel Ring simple sketch (c) 2013 Shae Erisson // released under the GPLv3 license to match the rest of the AdaFruit NeoPixel library #include <Adafruit_NeoPixel.h> #ifdef __AVR__ #include <avr/power.h> #endif // Which pin on the Arduino is connected to the NeoPixels? // On a Trinket or Gemma we suggest changing this to 1 #define PIN 6 // How many NeoPixels are attached to the Arduino? #define NUMPIXELS 16 // When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals. // Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest // example for more information on possible values. Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); int delayval = 500; // delay for half a second void setup() { // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket #if defined (__AVR_ATtiny85__) if (F_CPU == 16000000) clock_prescale_set(clock_div_1); #endif // End of trinket special code pixels.begin(); // This initializes the NeoPixel library. } void loop() { // For a set of NeoPixels the first NeoPixel is 0, second is 1, all the way up to the count of pixels minus one. for(int i=0;i<NUMPIXELS;i++){ // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255 pixels.setPixelColor(i, pixels.Color(0,150,0)); // Moderately bright green color. pixels.show(); // This sends the updated pixel color to the hardware. delay(delayval); // Delay for a period of time (in milliseconds). } }