void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
}
}
Primer 5: Knightrider
int counter = 1;
void setup() {
DDRD = 0xFF; // Celoten PORT D kot izhod
}
void loop() {
for ( int x = 0; x < 8; x++){
PORTD = counter;
delay(100);
counter *= 2;
if (counter > 128) counter /= 2;
}
for ( int x = 0; x < 8; x++){
PORTD = counter;
counter = counter /2;
if (counter < 1) counter = 1;
delay(100);
}
}
Primer 6: Knightrider z uporabo funkcije millis()
int timeDelay = 200;
unsigned long changeTime;
int counter = 1;
int direction = 1;
void setup() {
DDRD = 0xFF; //Celoten PORT D kot izhod
changeTime = millis();
}
void loop() {
PORTD = counter;
if ((millis() - changeTime) > timeDelay){
if (direction == 1) {
counter = counter *2;
}
else counter /= 2;
changeTime = millis();
if (counter > 64) direction = 0;
if (counter <= 1) direction = 1;
}
}
Primer 7: Knightrider z uporabo funkcije millis() in tipko za določitev smeri
byte value = 0;
int ledDelay = 500;
unsigned long changeTime;
int counter = 0;
void setup() {
DDRD |= B11111111; // PORTD kot OUTPUT
DDRB |= B00000000; // PORTB kot INPUT
PORTD = 0;
}
void loop() {
value = PINB & B00000001; // filter
if ((millis() - changeTime) > ledDelay){
if ( value == 0) {
if (counter > 128 || counter < 1) counter = 1;
PORTD = counter;
counter = counter *2;
}
if ( value == 1) {
if (counter <= 0 || counter > 128) counter = 128;
PORTD = counter;
counter = counter /2;
}
changeTime = millis();
}
}
Primer 8: Light show
int ledPin[] = {1, 2, 4, 8, 16, 32, 64, 128, 255, 0, 255};
void setup() {
DDRD |= 0xFF; // PORT D kot izhod
PORTD = 0;
Serial.begin(115200);
}
void loop() {
for ( int x = 0; x < (sizeof(ledPin) / sizeof(ledPin[0])); x++ ){
PORTD = ledPin[x];
delay(400);
Serial.println(sizeof(ledPin) / sizeof(ledPin[0])); //divide the total size of the array by the size of the array element
}
}
Primer 9: Light show z izbiro utripanja
int ledPin[] = {1, 2, 4, 8, 16, 32, 64, 128};
int ledPin1[] = {255, 0, 255, 0};
void setup() {
DDRD |= 0xFF; //Port D2 kot izhod
PORTD = 0;
DDRB |= B00000000; // PortB kot vhod
//Serial.begin(115200);
}
void loop() {
int value = PINB & B00000001;
if(value == HIGH)
{
for ( int x = 0; x < (sizeof(ledPin) / sizeof(ledPin[0])); x++ ){
PORTD = ledPin[x];
if (value != PINB & B00000001) break;
delay(400);
//Serial.println(sizeof(ledPin) / sizeof(ledPin[0])); //divide the total size of the array by the size of the array element
}
}
else {
for ( int x = 0; x < (sizeof(ledPin1) / sizeof(ledPin1[0])); x++ ){
PORTD = ledPin1[x];
if (value != (PINB & B00000001)) break;
delay(400);
//Serial.println(sizeof(ledPin) / sizeof(ledPin[0])); //divide the total size of the array by the size of the array element
}
}
}
Primer 8A: Light show uporaba pinMode
https://wokwi.com/projects/381989265189558273
void setup(){
for(int x = 0; x < 8; x++){
pinMode(x, OUTPUT);
}
}
void loop(){
for(int x=0; x<8; x++){
digitalWrite(x,HIGH);
delay(500);
}
for(int x=8; x >= 0; x--){
digitalWrite(x,LOW);
delay(500);
}
}
Primer 8B: Light show uporaba pinMode
int digit[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
void setup() {
for ( int x = 0; x < 8; x++ ){
pinMode(x, OUTPUT);
}
}
void loop() {
int i = digit[2];
for( int x = 0; x < 8; x++){
int k = i & 0x01;
digitalWrite(x, k); ;
i >>= 1; // i = i >> 1
}
delay(500);
}
Primer 8C: Light show uporaba pinMode
int digit[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
int pin[8] = {0,1,2,3,4,5,6,7};
int x = 0;
void setup() {
for ( int x = 0; x < 8; x++ ){
pinMode(pin[x], OUTPUT);
}
}
void loop() {
int i = digit[x];
for( int x = 0; x < 8; x++){
int k = i & 0x01;
digitalWrite(pin[x], k);
i >>= 1; // i = i >> 1
}
delay(500);
x++;
}
Primer 10: Analogno digitalni pretvornik
int pinPot = 0;
void setup() {
DDRD = 0xFF;
DDRB |= 0x01;
DDRB &= 0b11111101;
}
void loop() {
int m = PINB & 0x02;
if (m == 0x02) PORTB &= !0x01;
else PORTB |=0x01;
int x = analogRead(pinPot);
x = map(x, 0, 1024, 0, 255);
PORTD = x;
}
}
}
Primer 5: Knightrider
int counter = 1;
void setup() {
DDRD = 0xFF; // Celoten PORT D kot izhod
}
void loop() {
for ( int x = 0; x < 8; x++){
PORTD = counter;
delay(100);
counter *= 2;
if (counter > 128) counter /= 2;
}
for ( int x = 0; x < 8; x++){
PORTD = counter;
counter = counter /2;
if (counter < 1) counter = 1;
delay(100);
}
}
Primer 6: Knightrider z uporabo funkcije millis()
int timeDelay = 200;
unsigned long changeTime;
int counter = 1;
int direction = 1;
void setup() {
DDRD = 0xFF; //Celoten PORT D kot izhod
changeTime = millis();
}
void loop() {
PORTD = counter;
if ((millis() - changeTime) > timeDelay){
if (direction == 1) {
counter = counter *2;
}
else counter /= 2;
changeTime = millis();
if (counter > 64) direction = 0;
if (counter <= 1) direction = 1;
}
}
Primer 7: Knightrider z uporabo funkcije millis() in tipko za določitev smeri
byte value = 0;
int ledDelay = 500;
unsigned long changeTime;
int counter = 0;
void setup() {
DDRD |= B11111111; // PORTD kot OUTPUT
DDRB |= B00000000; // PORTB kot INPUT
PORTD = 0;
}
void loop() {
value = PINB & B00000001; // filter
if ((millis() - changeTime) > ledDelay){
if ( value == 0) {
if (counter > 128 || counter < 1) counter = 1;
PORTD = counter;
counter = counter *2;
}
if ( value == 1) {
if (counter <= 0 || counter > 128) counter = 128;
PORTD = counter;
counter = counter /2;
}
changeTime = millis();
}
}
Primer 8: Light show
int ledPin[] = {1, 2, 4, 8, 16, 32, 64, 128, 255, 0, 255};
void setup() {
DDRD |= 0xFF; // PORT D kot izhod
PORTD = 0;
Serial.begin(115200);
}
void loop() {
for ( int x = 0; x < (sizeof(ledPin) / sizeof(ledPin[0])); x++ ){
PORTD = ledPin[x];
delay(400);
Serial.println(sizeof(ledPin) / sizeof(ledPin[0])); //divide the total size of the array by the size of the array element
}
}
Primer 9: Light show z izbiro utripanja
int ledPin[] = {1, 2, 4, 8, 16, 32, 64, 128};
int ledPin1[] = {255, 0, 255, 0};
void setup() {
DDRD |= 0xFF; //Port D2 kot izhod
PORTD = 0;
DDRB |= B00000000; // PortB kot vhod
//Serial.begin(115200);
}
void loop() {
int value = PINB & B00000001;
if(value == HIGH)
{
for ( int x = 0; x < (sizeof(ledPin) / sizeof(ledPin[0])); x++ ){
PORTD = ledPin[x];
if (value != PINB & B00000001) break;
delay(400);
//Serial.println(sizeof(ledPin) / sizeof(ledPin[0])); //divide the total size of the array by the size of the array element
}
}
else {
for ( int x = 0; x < (sizeof(ledPin1) / sizeof(ledPin1[0])); x++ ){
PORTD = ledPin1[x];
if (value != (PINB & B00000001)) break;
delay(400);
//Serial.println(sizeof(ledPin) / sizeof(ledPin[0])); //divide the total size of the array by the size of the array element
}
}
}
Primer 8A: Light show uporaba pinMode
https://wokwi.com/projects/381989265189558273
void setup(){
for(int x = 0; x < 8; x++){
pinMode(x, OUTPUT);
}
}
void loop(){
for(int x=0; x<8; x++){
digitalWrite(x,HIGH);
delay(500);
}
for(int x=8; x >= 0; x--){
digitalWrite(x,LOW);
delay(500);
}
}
Primer 8B: Light show uporaba pinMode
int digit[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
void setup() {
for ( int x = 0; x < 8; x++ ){
pinMode(x, OUTPUT);
}
}
void loop() {
int i = digit[2];
for( int x = 0; x < 8; x++){
int k = i & 0x01;
digitalWrite(x, k); ;
i >>= 1; // i = i >> 1
}
delay(500);
}
Primer 8C: Light show uporaba pinMode
int digit[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
int pin[8] = {0,1,2,3,4,5,6,7};
int x = 0;
void setup() {
for ( int x = 0; x < 8; x++ ){
pinMode(pin[x], OUTPUT);
}
}
void loop() {
int i = digit[x];
for( int x = 0; x < 8; x++){
int k = i & 0x01;
digitalWrite(pin[x], k);
i >>= 1; // i = i >> 1
}
delay(500);
x++;
}
Primer 10: Analogno digitalni pretvornik
int pinPot = 0;
void setup() {
DDRD = 0xFF;
DDRB |= 0x01;
DDRB &= 0b11111101;
}
void loop() {
int m = PINB & 0x02;
if (m == 0x02) PORTB &= !0x01;
else PORTB |=0x01;
int x = analogRead(pinPot);
x = map(x, 0, 1024, 0, 255);
PORTD = x;
}
}
}
Primer 5: Knightrider
int counter = 1;
void setup() {
DDRD = 0xFF; // Celoten PORT D kot izhod
}
void loop() {
for ( int x = 0; x < 8; x++){
PORTD = counter;
delay(100);
counter *= 2;
if (counter > 128) counter /= 2;
}
for ( int x = 0; x < 8; x++){
PORTD = counter;
counter = counter /2;
if (counter < 1) counter = 1;
delay(100);
}
}
Primer 6: Knightrider z uporabo funkcije millis()
int timeDelay = 200;
unsigned long changeTime;
int counter = 1;
int direction = 1;
void setup() {
DDRD = 0xFF; //Celoten PORT D kot izhod
changeTime = millis();
}
void loop() {
PORTD = counter;
if ((millis() - changeTime) > timeDelay){
if (direction == 1) {
counter = counter *2;
}
else counter /= 2;
changeTime = millis();
if (counter > 64) direction = 0;
if (counter <= 1) direction = 1;
}
}
Primer 7: Knightrider z uporabo funkcije millis() in tipko za določitev smeri
byte value = 0;
int ledDelay = 500;
unsigned long changeTime;
int counter = 0;
void setup() {
DDRD |= B11111111; // PORTD kot OUTPUT
DDRB |= B00000000; // PORTB kot INPUT
PORTD = 0;
}
void loop() {
value = PINB & B00000001; // filter
if ((millis() - changeTime) > ledDelay){
if ( value == 0) {
if (counter > 128 || counter < 1) counter = 1;
PORTD = counter;
counter = counter *2;
}
if ( value == 1) {
if (counter <= 0 || counter > 128) counter = 128;
PORTD = counter;
counter = counter /2;
}
changeTime = millis();
}
}
Primer 8: Light show
int ledPin[] = {1, 2, 4, 8, 16, 32, 64, 128, 255, 0, 255};
void setup() {
DDRD |= 0xFF; // PORT D kot izhod
PORTD = 0;
Serial.begin(115200);
}
void loop() {
for ( int x = 0; x < (sizeof(ledPin) / sizeof(ledPin[0])); x++ ){
PORTD = ledPin[x];
delay(400);
Serial.println(sizeof(ledPin) / sizeof(ledPin[0])); //divide the total size of the array by the size of the array element
}
}
Primer 9: Light show z izbiro utripanja
int ledPin[] = {1, 2, 4, 8, 16, 32, 64, 128};
int ledPin1[] = {255, 0, 255, 0};
void setup() {
DDRD |= 0xFF; //Port D2 kot izhod
PORTD = 0;
DDRB |= B00000000; // PortB kot vhod
//Serial.begin(115200);
}
void loop() {
int value = PINB & B00000001;
if(value == HIGH)
{
for ( int x = 0; x < (sizeof(ledPin) / sizeof(ledPin[0])); x++ ){
PORTD = ledPin[x];
if (value != PINB & B00000001) break;
delay(400);
//Serial.println(sizeof(ledPin) / sizeof(ledPin[0])); //divide the total size of the array by the size of the array element
}
}
else {
for ( int x = 0; x < (sizeof(ledPin1) / sizeof(ledPin1[0])); x++ ){
PORTD = ledPin1[x];
if (value != (PINB & B00000001)) break;
delay(400);
//Serial.println(sizeof(ledPin) / sizeof(ledPin[0])); //divide the total size of the array by the size of the array element
}
}
}
Primer 8A: Light show uporaba pinMode
https://wokwi.com/projects/381989265189558273
void setup(){
for(int x = 0; x < 8; x++){
pinMode(x, OUTPUT);
}
}
void loop(){
for(int x=0; x<8; x++){
digitalWrite(x,HIGH);
delay(500);
}
for(int x=8; x >= 0; x--){
digitalWrite(x,LOW);
delay(500);
}
}
Primer 8B: Light show uporaba pinMode
int digit[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
void setup() {
for ( int x = 0; x < 8; x++ ){
pinMode(x, OUTPUT);
}
}
void loop() {
int i = digit[2];
for( int x = 0; x < 8; x++){
int k = i & 0x01;
digitalWrite(x, k); ;
i >>= 1; // i = i >> 1
}
delay(500);
}
Primer 8C: Light show uporaba pinMode
int digit[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
int pin[8] = {0,1,2,3,4,5,6,7};
int x = 0;
void setup() {
for ( int x = 0; x < 8; x++ ){
pinMode(pin[x], OUTPUT);
}
}
void loop() {
int i = digit[x];
for( int x = 0; x < 8; x++){
int k = i & 0x01;
digitalWrite(pin[x], k);
i >>= 1; // i = i >> 1
}
delay(500);
x++;
}
Primer 10: Analogno digitalni pretvornik
int pinPot = 0;
void setup() {
DDRD = 0xFF;
DDRB |= 0x01;
DDRB &= 0b11111101;
}
void loop() {
int m = PINB & 0x02;
if (m == 0x02) PORTB &= !0x01;
else PORTB |=0x01;
int x = analogRead(pinPot);
x = map(x, 0, 1024, 0, 255);
PORTD = x;
}
}
}
Primer 5: Knightrider
int counter = 1;
void setup() {
DDRD = 0xFF; // Celoten PORT D kot izhod
}
void loop() {
for ( int x = 0; x < 8; x++){
PORTD = counter;
delay(100);
counter *= 2;
if (counter > 128) counter /= 2;
}
for ( int x = 0; x < 8; x++){
PORTD = counter;
counter = counter /2;
if (counter < 1) counter = 1;
delay(100);
}
}
Primer 6: Knightrider z uporabo funkcije millis()
int timeDelay = 200;
unsigned long changeTime;
int counter = 1;
int direction = 1;
void setup() {
DDRD = 0xFF; //Celoten PORT D kot izhod
changeTime = millis();
}
void loop() {
PORTD = counter;
if ((millis() - changeTime) > timeDelay){
if (direction == 1) {
counter = counter *2;
}
else counter /= 2;
changeTime = millis();
if (counter > 64) direction = 0;
if (counter <= 1) direction = 1;
}
}
Primer 7: Knightrider z uporabo funkcije millis() in tipko za določitev smeri
byte value = 0;
int ledDelay = 500;
unsigned long changeTime;
int counter = 0;
void setup() {
DDRD |= B11111111; // PORTD kot OUTPUT
DDRB |= B00000000; // PORTB kot INPUT
PORTD = 0;
}
void loop() {
value = PINB & B00000001; // filter
if ((millis() - changeTime) > ledDelay){
if ( value == 0) {
if (counter > 128 || counter < 1) counter = 1;
PORTD = counter;
counter = counter *2;
}
if ( value == 1) {
if (counter <= 0 || counter > 128) counter = 128;
PORTD = counter;
counter = counter /2;
}
changeTime = millis();
}
}
Primer 8: Light show
int ledPin[] = {1, 2, 4, 8, 16, 32, 64, 128, 255, 0, 255};
void setup() {
DDRD |= 0xFF; // PORT D kot izhod
PORTD = 0;
Serial.begin(115200);
}
void loop() {
for ( int x = 0; x < (sizeof(ledPin) / sizeof(ledPin[0])); x++ ){
PORTD = ledPin[x];
delay(400);
Serial.println(sizeof(ledPin) / sizeof(ledPin[0])); //divide the total size of the array by the size of the array element
}
}
Primer 9: Light show z izbiro utripanja
int ledPin[] = {1, 2, 4, 8, 16, 32, 64, 128};
int ledPin1[] = {255, 0, 255, 0};
void setup() {
DDRD |= 0xFF; //Port D2 kot izhod
PORTD = 0;
DDRB |= B00000000; // PortB kot vhod
//Serial.begin(115200);
}
void loop() {
int value = PINB & B00000001;
if(value == HIGH)
{
for ( int x = 0; x < (sizeof(ledPin) / sizeof(ledPin[0])); x++ ){
PORTD = ledPin[x];
if (value != PINB & B00000001) break;
delay(400);
//Serial.println(sizeof(ledPin) / sizeof(ledPin[0])); //divide the total size of the array by the size of the array element
}
}
else {
for ( int x = 0; x < (sizeof(ledPin1) / sizeof(ledPin1[0])); x++ ){
PORTD = ledPin1[x];
if (value != (PINB & B00000001)) break;
delay(400);
//Serial.println(sizeof(ledPin) / sizeof(ledPin[0])); //divide the total size of the array by the size of the array element
}
}
}
Primer 8A: Light show uporaba pinMode
https://wokwi.com/projects/381989265189558273
void setup(){
for(int x = 0; x < 8; x++){
pinMode(x, OUTPUT);
}
}
void loop(){
for(int x=0; x<8; x++){
digitalWrite(x,HIGH);
delay(500);
}
for(int x=8; x >= 0; x--){
digitalWrite(x,LOW);
delay(500);
}
}
Primer 8B: Light show uporaba pinMode
int digit[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
void setup() {
for ( int x = 0; x < 8; x++ ){
pinMode(x, OUTPUT);
}
}
void loop() {
int i = digit[2];
for( int x = 0; x < 8; x++){
int k = i & 0x01;
digitalWrite(x, k); ;
i >>= 1; // i = i >> 1
}
delay(500);
}
Primer 8C: Light show uporaba pinMode
int digit[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
int pin[8] = {0,1,2,3,4,5,6,7};
int x = 0;
void setup() {
for ( int x = 0; x < 8; x++ ){
pinMode(pin[x], OUTPUT);
}
}
void loop() {
int i = digit[x];
for( int x = 0; x < 8; x++){
int k = i & 0x01;
digitalWrite(pin[x], k);
i >>= 1; // i = i >> 1
}
delay(500);
x++;
}
Primer 10: Analogno digitalni pretvornik
int pinPot = 0;
void setup() {
DDRD = 0xFF;
DDRB |= 0x01;
DDRB &= 0b11111101;
}
void loop() {
int m = PINB & 0x02;
if (m == 0x02) PORTB &= !0x01;
else PORTB |=0x01;
int x = analogRead(pinPot);
x = map(x, 0, 1024, 0, 255);
PORTD = x;
}
}
}
Primer 5: Knightrider
int counter = 1;
void setup() {
DDRD = 0xFF; // Celoten PORT D kot izhod
}
void loop() {
for ( int x = 0; x < 8; x++){
PORTD = counter;
delay(100);
counter *= 2;
if (counter > 128) counter /= 2;
}
for ( int x = 0; x < 8; x++){
PORTD = counter;
counter = counter /2;
if (counter < 1) counter = 1;
delay(100);
}
}
Primer 6: Knightrider z uporabo funkcije millis()
int timeDelay = 200;
unsigned long changeTime;
int counter = 1;
int direction = 1;
void setup() {
DDRD = 0xFF; //Celoten PORT D kot izhod
changeTime = millis();
}
void loop() {
PORTD = counter;
if ((millis() - changeTime) > timeDelay){
if (direction == 1) {
counter = counter *2;
}
else counter /= 2;
changeTime = millis();
if (counter > 64) direction = 0;
if (counter <= 1) direction = 1;
}
}
Primer 7: Knightrider z uporabo funkcije millis() in tipko za določitev smeri
byte value = 0;
int ledDelay = 500;
unsigned long changeTime;
int counter = 0;
void setup() {
DDRD |= B11111111; // PORTD kot OUTPUT
DDRB |= B00000000; // PORTB kot INPUT
PORTD = 0;
}
void loop() {
value = PINB & B00000001; // filter
if ((millis() - changeTime) > ledDelay){
if ( value == 0) {
if (counter > 128 || counter < 1) counter = 1;
PORTD = counter;
counter = counter *2;
}
if ( value == 1) {
if (counter <= 0 || counter > 128) counter = 128;
PORTD = counter;
counter = counter /2;
}
changeTime = millis();
}
}
Primer 8: Light show
int ledPin[] = {1, 2, 4, 8, 16, 32, 64, 128, 255, 0, 255};
void setup() {
DDRD |= 0xFF; // PORT D kot izhod
PORTD = 0;
Serial.begin(115200);
}
void loop() {
for ( int x = 0; x < (sizeof(ledPin) / sizeof(ledPin[0])); x++ ){
PORTD = ledPin[x];
delay(400);
Serial.println(sizeof(ledPin) / sizeof(ledPin[0])); //divide the total size of the array by the size of the array element
}
}
Primer 9: Light show z izbiro utripanja
int ledPin[] = {1, 2, 4, 8, 16, 32, 64, 128};
int ledPin1[] = {255, 0, 255, 0};
void setup() {
DDRD |= 0xFF; //Port D2 kot izhod
PORTD = 0;
DDRB |= B00000000; // PortB kot vhod
//Serial.begin(115200);
}
void loop() {
int value = PINB & B00000001;
if(value == HIGH)
{
for ( int x = 0; x < (sizeof(ledPin) / sizeof(ledPin[0])); x++ ){
PORTD = ledPin[x];
if (value != PINB & B00000001) break;
delay(400);
//Serial.println(sizeof(ledPin) / sizeof(ledPin[0])); //divide the total size of the array by the size of the array element
}
}
else {
for ( int x = 0; x < (sizeof(ledPin1) / sizeof(ledPin1[0])); x++ ){
PORTD = ledPin1[x];
if (value != (PINB & B00000001)) break;
delay(400);
//Serial.println(sizeof(ledPin) / sizeof(ledPin[0])); //divide the total size of the array by the size of the array element
}
}
}
Primer 8A: Light show uporaba pinMode
https://wokwi.com/projects/381989265189558273
void setup(){
for(int x = 0; x < 8; x++){
pinMode(x, OUTPUT);
}
}
void loop(){
for(int x=0; x<8; x++){
digitalWrite(x,HIGH);
delay(500);
}
for(int x=8; x >= 0; x--){
digitalWrite(x,LOW);
delay(500);
}
}
Primer 8B: Light show uporaba pinMode
int digit[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
void setup() {
for ( int x = 0; x < 8; x++ ){
pinMode(x, OUTPUT);
}
}
void loop() {
int i = digit[2];
for( int x = 0; x < 8; x++){
int k = i & 0x01;
digitalWrite(x, k); ;
i >>= 1; // i = i >> 1
}
delay(500);
}
Primer 8C: Light show uporaba pinMode
int digit[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
int pin[8] = {0,1,2,3,4,5,6,7};
int x = 0;
void setup() {
for ( int x = 0; x < 8; x++ ){
pinMode(pin[x], OUTPUT);
}
}
void loop() {
int i = digit[x];
for( int x = 0; x < 8; x++){
int k = i & 0x01;
digitalWrite(pin[x], k);
i >>= 1; // i = i >> 1
}
delay(500);
x++;
}
Primer 10: Analogno digitalni pretvornik
int pinPot = 0;
void setup() {
DDRD = 0xFF;
DDRB |= 0x01;
DDRB &= 0b11111101;
}
void loop() {
int m = PINB & 0x02;
if (m == 0x02) PORTB &= !0x01;
else PORTB |=0x01;
int x = analogRead(pinPot);
x = map(x, 0, 1024, 0, 255);
PORTD = x;
}