Hi Bela,
Here is the code:
[code]/*
This example code is in the public domain.
http://arduino.cc/en/Tutorial/ButtonStateChange
*/
//#include <TinyWireM.h>
#include <Wire.h>
#include “Adafruit_LEDBackpack.h”
#include “Adafruit_GFX.h”
const int button1Pin = 3; // button pin on RePhone pad A1
const int button2Pin = 4; // button pin on RePhone pad E2
Adafruit_8x8matrix matrix = Adafruit_8x8matrix();
// Variables will change:
int button1PushCounter = 0; // counter for the number of button1 presses
int button1State = 0; // current state of the button1
int lastButton1State = 0; // previous state of the button1
int button2PushCounter = 0; // counter for the number of button2 presses
int button2State = 0; // current state of the button2
int lastButton2State = 0; // previous state of the button2
void setup() {
// initialize the button pin as a input:
pinMode(button1Pin, INPUT);
pinMode(button2Pin, INPUT);
matrix.begin(0x70); // pass in the address
}
static const uint8_t PROGMEM // X and square bitmaps
smile_bmp[] =
{ B00111100,
B01000010,
B10100101,
B10000001,
B10100101,
B10011001,
B01000010,
B00111100
},
hearth_bmp[] =
{ B00100100,
B01011010,
B10011001,
B10000001,
B10000001,
B01000010,
B00100100,
B00011000
},
flower_bmp[] =
{ B11000011,
B10100101,
B01100110,
B00011000,
B01111011,
B10101110,
B11001100,
B00001000
};
void loop() {
// read the pushbutton input pin:
button1State = digitalRead(button1Pin);
button2State = digitalRead(button2Pin);
// compare the buttonState to its previous state
if (button1State != lastButton1State) {
// if the state has changed, increment the counter
if (button1State == HIGH && lastButton1State == LOW) {
// if the current state is HIGH then the button
// went from off to on:
button1PushCounter++;
} else {
// if the current state is LOW then the button
// went from on to off:
}
}
// save the current state as the last state,
//for next time through the loop
lastButton1State = button1State;
// turns on the LED every four button pushes by
// checking the modulo of the button push counter.
// the modulo function gives you the remainder of
// the division of two numbers:
switch (button1PushCounter % 3)
{
case 0:
matrix.clear();
matrix.drawBitmap(0, 0, hearth_bmp, 8, 8, LED_ON);
matrix.writeDisplay();
button1State = HIGH;
break;
case 1:
matrix.clear();
matrix.drawBitmap(0, 0, smile_bmp, 8, 8, LED_ON);
matrix.writeDisplay();
button1State = HIGH;
break;
case 2:
matrix.clear();
matrix.drawBitmap(0, 0, flower_bmp, 8, 8, LED_ON);
matrix.writeDisplay();
button1State = HIGH;
}
if (button2State != lastButton2State) {
// if the state has changed, increment the counter
if (button2State == HIGH && lastButton2State == LOW) {
// if the current state is HIGH then the button
// went from off to on:
button2PushCounter++;
} else {
// if the current state is LOW then the button
// went from on to off:
}
}
// save the current state as the last state,
//for next time through the loop
lastButton2State = button2State;
// turns on the LED every four button pushes by
// checking the modulo of the button push counter.
// the modulo function gives you the remainder of
// the division of two numbers:
switch (button2PushCounter % 3)
{
case 0:
matrix.clear();
matrix.drawBitmap(0, 0, flower_bmp, 8, 8, LED_ON);
matrix.writeDisplay();
button1State = HIGH;
break;
case 1:
matrix.clear();
matrix.drawBitmap(0, 0, smile_bmp, 8, 8, LED_ON);
matrix.writeDisplay();
button1State = HIGH;
break;
case 2:
matrix.clear();
matrix.drawBitmap(0, 0, hearth_bmp, 8, 8, LED_ON);
matrix.writeDisplay();
button1State = HIGH;
}
}
[/code]
And here is what I am trying to achieve:
I have three pictogram’s: flower, smile and hearth. Every time the button 1 is pressed will display a next pictogram scrolling trough them on every press from Smile to Flower to Hearth and repeat again.
When the button 2 is pressed it will display the pictogram on the reverse direction. I know the code is not perfect but on Flora or Gemma I have the pictogram’s displayed fully and correctly therefore I am thinking the issue is with the libraries;
Wire.h on RePhone vs the TinyWireM.h on Flora that gives me an error on RePhone.
Thanks!