Annnnd.... the worst result in science: inconsistent results.
But they're results.
Code: Select all#include <SoftwareSerial.h>
SoftwareSerial mySerial(2,3);
// These constants won't change. They're used to give names
// to the pins used:
const int analogInPin = A5; // Analog input pin that the potentiometer is attached to
const int analogOutPin = 9; // Analog output pin that the LED is attached to
int sensorValue = 0; // value read from the pot
int outputValue = 0; // value output to the PWM (analog out)
//int sensorArray[] = {1,0}; // array to store the sensorValue
//int outputArray[] = {2,0}; //array to store the outputValue
String sensorString = "10"; //string to store the sensorValue
String outputString = "20"; //string to store the outputValue
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(115200);
mySerial.begin(57600);
}
void loop() {
// read the analog in value:
sensorValue = analogRead(analogInPin);
// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 0, 255);
// change the analog out value:
//sensorArray[1] = sensorValue;
//outputArray[1] = outputValue;
sensorString[1] = sensorValue;
outputString[1] = outputValue;
analogWrite(analogOutPin, outputValue);
// print the results to the serial monitor:
//Serial.print("sensor = " );
//Serial.print(sensorValue);
//Serial.print("\t output = ");
//Serial.println(outputValue);
//Serial.print(sensorArray[0]);
//Serial.print(" ");
//Serial.print(sensorArray[1]);
//Serial.print("\t");
//Serial.print(outputArray[0]);
//Serial.print(" ");
//Serial.println(outputArray[1]);
Serial.print(sensorString);
Serial.print("\t");
Serial.println(outputString);
mySerial.print(sensorString);
mySerial.print("\t");
mySerial.println(outputString);
// wait 500 milliseconds before the next loop
// for the analog-to-digital converter to settle
// after the last reading:
delay(50);
}
This is the Arduino code
Eventually, I want the Arduino to send out two packets of information: A message identifier and the message "text" itself (Yeah, this is what we've been talking about for a week, but I'm just talking out loud here). The message identifier is one byte long. Anything less and it takes up the same amount of room (right?). The message "text" itself may be multiple bytes long. The entire message will be tab-separated and carriage return (new line? same thing?) terminated.
I need to get the display to show the data in this format (Message ID-tab-Message Text-NL). Then I'm going to have the display start message slicing to put the right information in the right places on the display. Finally, I'll have the display start storing messages on the onboard uSD card (the current card is 16GB. I think we have space).
Below is the code for the uOLED Display. This IS NOT ARDUINO CODE.
Code: Select all#platform "GOLDELOX-GFX2"
/*
Serial display for the airsoft smartgun developed by StaticDet5
This program takes the serial input and displays it to the screen
Tested:
4-17-2012 Program appears to display the correct symbols
*/
#inherit "4DGL_16bitColours.fnc"
var combuf[8];
var j;
var chr;
func main()
gfx_Set(OUTLINE_COLOUR, DARKOLIVEGREEN);
gfx_Cls();
txt_Set(FONT_ID, 0);
txt_MoveCursor(0,1);
setbaud(BAUD_57600);
com_Init(combuf, 16, 0);
repeat
gfx_Set(OUTLINE_COLOUR, DARKOLIVEGREEN);
//gfx_Cls();
j :=0;
txt_MoveCursor(3,1);
putch(combuf);
chr := serin();
txt_MoveCursor(3,1);
putch(chr);
/*while ( (chr := serin()) >= 0)
txt_MoveCursor(3,1);
putch(" ");
txt_MoveCursor(3,(1+j));
putch(chr);
to(COM0); putch(chr); // send buffered chars to com port
j++;
wend
*/
//pause(100);
forever
endfunc
The code is really there because I'm talking out loud. Someone else coming behind me can see where I'm making mistakes.
I think the problem with displaying the entire message is in the display code. I only have it pulling the first character from the serial buffer. When I had it trying to iterate over the buffer, it wasn't displaying anything. That's the "While" section that is commented out.
However, this code is displaying character changes that correlate to the changing pot on the Arduino serial test. I just need to get a little further.