added simple tutorials, modified RESET pin

This commit is contained in:
JP
2014-06-09 11:01:47 +10:00
parent 8db48a9538
commit fd26958cff
4 changed files with 353 additions and 5 deletions

View File

@@ -108,7 +108,9 @@ void MicroView::begin() {
setColor(WHITE);
setDrawMode(NORM);
setCursor(0,0);
pinMode(OLEDPWR, OUTPUT);
digitalWrite(OLEDPWR,HIGH);
// Setting up SPI pins
pinMode(MOSI, OUTPUT);
pinMode(SCK, OUTPUT);
@@ -243,7 +245,7 @@ void MicroView::clear(uint8_t mode) {
else
{
memset(screenmemory,0,384); // (64 x 48) / 8 = 384
display();
//display();
}
}

View File

@@ -25,7 +25,8 @@
#define swap(a, b) { uint8_t t = a; a = b; b = t; }
#define DC 8
#define RESET 12
#define RESET 7
#define OLEDPWR 4
// SS, SCK, MOSI already defined by original pins_arduino.h
//#define CS 10

View File

@@ -91,6 +91,10 @@ void loop() {
</code></pre>
## History
**v1.11b: 9th June 2014 by JP Liew**
* added simple tutorials for production sketch
* modified OLED RESET pin to 7
**v1.10b: 22th April 2014 by JP Liew**
* changed SS, RESET, DC pins to use weak internal pull-up resistors

View File

@@ -3,7 +3,7 @@
#define clocksize 24
uint8_t onDelay=5; // this is the on delay in milliseconds, if there is no on delay, the erase will be too fast to clean up the screen.
uint16_t onDelay=5; // this is the on delay in milliseconds, if there is no on delay, the erase will be too fast to clean up the screen.
void setup() {
uView.begin(); // begin of MicroView
@@ -14,6 +14,334 @@ void setup() {
uView.clear(PAGE); // erase the memory buffer, when next uView.display() is called, the OLED will be cleared.
}
void displayConnect(char * value, char * text) {
int y=0;
uView.clear(PAGE);
uView.setCursor(0,y);
uView.print("Connect a");
if (strlen(value)>0) {
uView.setCursor(0,y+10);
uView.print(value);
uView.setCursor(0,y+20);
}
else
uView.setCursor(0,y+10);
uView.print(text);
uView.display();
}
void displayRemove(char * text) {
int y=0;
uView.clear(PAGE);
uView.setCursor(0,y);
uView.print("Well done!");
uView.setCursor(0,y+9);
uView.print("Remove the");
uView.setCursor(0,y+18);
uView.print(text);
uView.setCursor(0,y+27);
uView.print("to proceed");
uView.display();
}
int getXpos(int pin) {
byte xpos[] = {0,0,8,17,26,34,42,51,59,59,51,42,34,26,17,8,0};
return xpos[pin];
}
int getYpos(int pin) {
if ((pin >0) && (pin <9)) {
return 41;
}
else {
return 6;
}
}
void drawPin(int pin) {
int x,y, dir;
int color=WHITE;
if ((pin >0) && (pin <9)) {
dir=0;
}
else {
dir=1;
}
x=getXpos(pin);
y=getYpos(pin);
if (dir==0) {
uView.drawChar(x,y-10,pin+48,color,XOR);
uView.line(x,y,x,y+4,color,XOR);
x++;
uView.line(x,y,x,y+5,color,XOR);
x++;
uView.line(x,y,x,y+6,color,XOR);
x++;
uView.line(x,y,x,y+5,color,XOR);
x++;
uView.line(x,y,x,y+4,color,XOR);
}
else {
if (pin<10)
uView.drawChar(x,y+3,pin+48,color,XOR);
else {
char str[5];
sprintf(str, "%d", pin);
uView.drawChar(x,y+3,str[0],color,XOR);
uView.drawChar(x,y+11, str[1],color,XOR);
}
uView.line(x,y,x,y-4,color,XOR);
x++;
uView.line(x,y,x,y-5,color,XOR);
x++;
uView.line(x,y,x,y-6,color,XOR);
x++;
uView.line(x,y,x,y-5,color,XOR);
x++;
uView.line(x,y,x,y-4,color,XOR);
}
uView.display();
}
void fromPinToPin(int pin1, int pin2) {
int x1,y1,x2,y2;
x1=getXpos(pin1);
y1=getYpos(pin1);
x2=getXpos(pin2);
uView.line(x1+6,y1-6, x2-1, y1-6);
uView.display();
drawPin(pin1);
drawPin(pin2);
}
void doJumper(int pin1, int pin2) {
int result;
int sense;
switch(pin1) {
case 7: sense=A0; break;
case 6: sense=A1; break;
case 5: sense=A2; break;
case 4: sense=A3; break;
case 3: sense=A4; break;
case 2: sense=A5; break;
default: return;
}
displayConnect("","jumper");
pinMode(sense,INPUT);
digitalWrite(sense,HIGH);
result=digitalRead(sense);
while(result==1) {
fromPinToPin(pin1,pin2); // on
delay(300);
fromPinToPin(pin1,pin2); // off
delay(300);
fromPinToPin(pin1,pin2); // on
delay(300);
result=digitalRead(sense);
}
uView.clear(PAGE);
displayRemove("jumper");
result=digitalRead(sense);
while(result==0) {
result=digitalRead(sense);
}
uView.clear(PAGE);
uView.display();
}
void doResistor(int pin1, int pin2, int value, int LED) {
int result,result2;
int sense;
int analogValue;
int ledout;
char resvalue[20];
if (value==330)
analogValue=25;
else
analogValue=230;
switch(pin1) {
case 7: sense=A0; break;
case 6: sense=A1; break;
case 5: sense=A2; break;
case 4: sense=A3; break;
case 3: sense=A4; break;
case 2: sense=A5; break;
default: return;
}
sprintf(resvalue,"%d",value);
strcat(resvalue," ohm");
displayConnect(resvalue,"resistor");
pinMode(sense,INPUT);
digitalWrite(sense,HIGH);
while(1) {
fromPinToPin(pin1,pin2); // on
delay(300);
fromPinToPin(pin1,pin2); // off
delay(300);
fromPinToPin(pin1,pin2); // on
delay(300);
result=analogRead(sense);
Serial.println(result);
if ((result>(analogValue-20)) && (result<(analogValue+20))) {
break;
}
}
uView.clear(PAGE);
if (LED==0) {
displayRemove("resistor");
result=analogRead(sense);
while(1) {
result=analogRead(sense);
if(result>(analogValue+20))
break;
}
}
else {
uView.clear(PAGE);
int outpin=pin1-1;
switch(outpin) {
case 7: ledout=A0; break;
case 6: ledout=A1; break;
case 5: ledout=A2; break;
case 4: ledout=A3; break;
case 3: ledout=A4; break;
case 2: ledout=A5; break;
default: return;
}
pinMode(ledout,OUTPUT);
displayConnect("","LED");
fromPinToPin(pin1,pin2);
drawPin(pin1);
uView.display();
while(1) {
digitalWrite(ledout,HIGH);
fromPinToPin(pin1-1,pin1); // on
delay(300);
digitalWrite(ledout,LOW);
fromPinToPin(pin1-1,pin1); // off
delay(300);
result=analogRead(sense);
digitalWrite(ledout,HIGH);
fromPinToPin(pin1-1,pin1); // on
delay(300);
result2=analogRead(sense);
Serial.print(result);
Serial.print(",");
Serial.println(result2);
if ((result2-result)>400) {
Serial.println("LED is blinking...");
break;
}
}
uView.clear(PAGE);
uView.setCursor(0,0);
uView.print("Well done!");
uView.setCursor(0,10);
uView.print("The LED is");
uView.setCursor(0,20);
uView.print("BLINKING!");
uView.setCursor(0,40);
uView.print("Thanks.");
uView.display();
long longdly=millis();
while(1) {
digitalWrite(ledout,HIGH);
delay(300);
digitalWrite(ledout,LOW);
delay(300);
if ((millis()-longdly)>6000)
break;
}
}
}
void displayTry() {
int y=0;
uView.clear(PAGE);
uView.setCursor(0,y);
uView.print("Now you");
uView.setCursor(0,y+10);
uView.print("have seen");
uView.setCursor(0,y+20);
uView.print("our demo.");
uView.display();
delay(onDelay);
uView.clear(PAGE);
uView.setCursor(0,y);
uView.print("Let's try");
uView.setCursor(0,y+10);
uView.print("our");
uView.setCursor(0,y+20);
uView.print("built-in");
uView.setCursor(0,y+30);
uView.print("tutorials.");
uView.display();
delay(onDelay);
uView.clear(PAGE);
uView.setCursor(0,y);
uView.print("When you");
uView.setCursor(0,y+10);
uView.print("see PINs");
uView.setCursor(0,y+20);
uView.print("blinking,");
uView.setCursor(0,y+30);
uView.print("connect");
uView.setCursor(0,y+40);
uView.print("the PINs");
uView.display();
delay(onDelay);
uView.clear(PAGE);
uView.setCursor(0,y);
uView.print("to the");
uView.setCursor(0,y+10);
uView.print("component");
uView.setCursor(0,y+20);
uView.print("mentioned.");
uView.display();
delay(onDelay);
}
void displayEnd() {
int y=0;
uView.clear(PAGE);
uView.setCursor(0,y);
uView.print("Please");
uView.setCursor(0,y+10);
uView.print("proceed to");
uView.setCursor(0,y+20);
uView.print("MicroView");
uView.setCursor(0,y+30);
uView.print("website.");
uView.display();
delay(onDelay);
}
void loop() {
int i;
static double counter=99999;
@@ -235,7 +563,7 @@ void loop() {
counter--;
uView.display();
mSec=millis()+100;
}
}ggggg
}
uView.clear(PAGE);
@@ -260,6 +588,19 @@ void loop() {
}
}
uView.clear(PAGE);
// Simple Tutorial
uView.setFontType(0);
onDelay=3500; // set 3.5 second between each message
displayTry(); // show please try our tutorial
doJumper(5,8); // jumper tutorial
doJumper(3,8); // jumper
doJumper(2,8);
doResistor(4,8,330,0);
doResistor(4,8,10000,0);
doResistor(5,8,330,1); // Do resistor with LED ends the tutorial.
displayEnd();
uView.clear(PAGE);
}