Skip to content
Snippets Groups Projects
Commit 71e38c8f authored by Lucas Stratmann's avatar Lucas Stratmann
Browse files

Poti-module working

parent cf1ca736
No related branches found
No related tags found
No related merge requests found
...@@ -19,6 +19,8 @@ import tec.letsgoing.ardublock.simulator.simcode.datatypes.SimTypeInt; ...@@ -19,6 +19,8 @@ import tec.letsgoing.ardublock.simulator.simcode.datatypes.SimTypeInt;
import tec.letsgoing.ardublock.simulator.simcode.datatypes.SimTypeString; import tec.letsgoing.ardublock.simulator.simcode.datatypes.SimTypeString;
import tec.letsgoing.ardublock.simulator.simcode.functions.CodeExecuteFunction; import tec.letsgoing.ardublock.simulator.simcode.functions.CodeExecuteFunction;
import tec.letsgoing.ardublock.simulator.simcode.functions.SimCodeFunction; import tec.letsgoing.ardublock.simulator.simcode.functions.SimCodeFunction;
import tec.letsgoing.ardublock.simulator.simcode.io.CodeAnalogRead;
import tec.letsgoing.ardublock.simulator.simcode.io.CodeAnalogWrite;
import tec.letsgoing.ardublock.simulator.simcode.io.CodeDigitalWrite; import tec.letsgoing.ardublock.simulator.simcode.io.CodeDigitalWrite;
import tec.letsgoing.ardublock.simulator.simcode.math.CodeAdd; import tec.letsgoing.ardublock.simulator.simcode.math.CodeAdd;
import tec.letsgoing.ardublock.simulator.simcode.vars.CodeMillis; import tec.letsgoing.ardublock.simulator.simcode.vars.CodeMillis;
...@@ -26,6 +28,11 @@ import tec.letsgoing.ardublock.simulator.view.GUI; ...@@ -26,6 +28,11 @@ import tec.letsgoing.ardublock.simulator.view.GUI;
/** /**
* @author Lucas * @author Lucas
*
* Pinmapping:
* RGB: 9,10,11
* Poti: A5
* Button: 3,4,5
*/ */
public class Simulator implements Runnable, ActionListener { public class Simulator implements Runnable, ActionListener {
...@@ -179,32 +186,35 @@ public class Simulator implements Runnable, ActionListener { ...@@ -179,32 +186,35 @@ public class Simulator implements Runnable, ActionListener {
public static void main(String[] args) throws InterruptedException { public static void main(String[] args) throws InterruptedException {
Vector<SimCode> testSetup = new Vector<SimCode>(); Vector<SimCode> testSetup = new Vector<SimCode>();
Vector<SimCode> testLoop = new Vector<SimCode>(); Vector<SimCode> testLoop = new Vector<SimCode>();
int testdelay = 500; int testdelay = 200;
SimTypeBool b1 = new SimTypeBool(true); SimTypeBool b1 = new SimTypeBool(true);
SimTypeBool b0 = new SimTypeBool(false); SimTypeBool b0 = new SimTypeBool(false);
SimTypeString s1 = new SimTypeString("CodeString Test"); SimTypeString s1 = new SimTypeString("CodeString Test");
SimTypeInt d1 = new SimTypeInt(5); SimTypeInt d1 = new SimTypeInt(9);
SimTypeInt d5 = new SimTypeInt(23); SimTypeInt d5 = new SimTypeInt(5);
SimTypeInt d2 = new SimTypeInt(0); SimTypeInt d3 = new SimTypeInt(0);
SimTypeInt d3 = new SimTypeInt(1); SimTypeInt d9 = new SimTypeInt(9);
SimTypeInt delay = new SimTypeInt(testdelay); SimTypeInt delay = new SimTypeInt(testdelay);
SimTypeString s2 = new SimTypeString(d1); SimTypeString s2 = new SimTypeString(d1);
CodeAdd s5 = new CodeAdd(d1, d5); CodeAdd s5 = new CodeAdd(d1, d5);
testLoop.add(new CodeDigitalWrite(d2, b0)); //testLoop.add(new CodeDigitalWrite(d2, b0));
testLoop.add(new CodeDelay(delay)); //testLoop.add(new CodeDelay(delay));
testLoop.add(new CodeDigitalWrite(d2, b1)); //testLoop.add(new CodeDigitalWrite(d2, b1));
testLoop.add(new CodeDelay(delay)); //testLoop.add(new CodeDelay(delay));
Vector<SimCode> forVec = new Vector<SimCode>(); Vector<SimCode> forVec = new Vector<SimCode>();
forVec.add(new CodeDigitalWrite(d3, b1)); forVec.add(new CodeDigitalWrite(d3, b1));
forVec.add(new CodeDelay(delay)); forVec.add(new CodeDelay(delay));
forVec.add(new CodeDigitalWrite(d3, b0)); forVec.add(new CodeDigitalWrite(d3, b0));
forVec.add(new CodeDelay(delay)); forVec.add(new CodeDelay(delay));
testLoop.add(new CodeFor(d1, forVec)); //testLoop.add(new CodeFor(d1, forVec));
testLoop.add(new CodeSerialPrint(new SimTypeString(new CodeMillis()), b1)); //testLoop.add(new CodeSerialPrint(new SimTypeString(new CodeMillis()), b1));
testLoop.add(new CodeSerialPrint(new SimTypeString(new CodeAnalogRead(d5)),b1));
testLoop.add(new CodeAnalogWrite(d9,new SimTypeInt(new CodeAnalogRead(d5))));
testLoop.add(new CodeDelay(delay));
SimCodeFunction setupCode = new SimCodeFunction("setup", testSetup); SimCodeFunction setupCode = new SimCodeFunction("setup", testSetup);
SimCodeFunction loopCode = new SimCodeFunction("loop", testLoop); SimCodeFunction loopCode = new SimCodeFunction("loop", testLoop);
......
...@@ -65,6 +65,7 @@ public class GUI extends JFrame implements Runnable, ActionListener { ...@@ -65,6 +65,7 @@ public class GUI extends JFrame implements Runnable, ActionListener {
mainPane.add(createControlPanel(simu), BorderLayout.LINE_END); mainPane.add(createControlPanel(simu), BorderLayout.LINE_END);
mainPane.add(createSerialLog(), BorderLayout.PAGE_END); mainPane.add(createSerialLog(), BorderLayout.PAGE_END);
this.pack(); this.pack();
//this.setLocation(-1000, 0); Code to Run the Window on seconds screen
this.setVisible(true); this.setVisible(true);
} }
......
...@@ -79,15 +79,15 @@ public class Button extends Modul implements ActionListener { ...@@ -79,15 +79,15 @@ public class Button extends Modul implements ActionListener {
} }
public boolean connect(Arduino arduino) { public boolean connect(Arduino arduino) {
Pin tmpPin = arduino.getPin(11); Pin tmpPin = arduino.getPin(3);
this.addPin(tmpPin); this.addPin(tmpPin);
tmpPin.setObserver(this); tmpPin.setObserver(this);
tmpPin = arduino.getPin(12); tmpPin = arduino.getPin(4);
this.addPin(tmpPin); this.addPin(tmpPin);
tmpPin.setObserver(this); tmpPin.setObserver(this);
tmpPin = arduino.getPin(13); tmpPin = arduino.getPin(5);
this.addPin(tmpPin); this.addPin(tmpPin);
tmpPin.setObserver(this); tmpPin.setObserver(this);
......
...@@ -6,6 +6,10 @@ package tec.letsgoing.ardublock.simulator.view.modules; ...@@ -6,6 +6,10 @@ package tec.letsgoing.ardublock.simulator.view.modules;
import java.awt.Dimension; import java.awt.Dimension;
import javax.swing.ImageIcon; import javax.swing.ImageIcon;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import tec.letsgoing.ardublock.simulator.arduino.Arduino; import tec.letsgoing.ardublock.simulator.arduino.Arduino;
import tec.letsgoing.ardublock.simulator.arduino.Pin; import tec.letsgoing.ardublock.simulator.arduino.Pin;
...@@ -14,8 +18,9 @@ import tec.letsgoing.ardublock.simulator.arduino.Pin; ...@@ -14,8 +18,9 @@ import tec.letsgoing.ardublock.simulator.arduino.Pin;
* @author Lucas * @author Lucas
* *
*/ */
public class Poti extends Modul { public class Poti extends Modul implements ChangeListener {
int value = 0; int value = 0;
JSlider slider;
public Poti(ImageIcon _icon) { public Poti(ImageIcon _icon) {
layerpane.setPreferredSize(new Dimension(294, 294)); layerpane.setPreferredSize(new Dimension(294, 294));
...@@ -23,16 +28,43 @@ public class Poti extends Modul { ...@@ -23,16 +28,43 @@ public class Poti extends Modul {
ImageIcon chipIcon = _icon; ImageIcon chipIcon = _icon;
chiplabel.setIcon(chipIcon); chiplabel.setIcon(chipIcon);
chiplabel.setSize(294, 294); chiplabel.setSize(294, 294);
layerpane.add(chiplabel, 1); slider=new JSlider(JSlider.HORIZONTAL,0,1024,512);
slider.setMajorTickSpacing(256);
slider.setMinorTickSpacing(64);
slider.setPaintTicks(true);
slider.setPaintLabels(true);
slider.setPreferredSize(new Dimension(180,50));
slider.setOpaque(false);
slider.addChangeListener(this);
JPanel sliderPanel=new JPanel();
sliderPanel.add(slider);
sliderPanel.setSize(200, 50);
sliderPanel.setLocation(47,170);
sliderPanel.setOpaque(false);
layerpane.add(chiplabel, 0);
layerpane.add(sliderPanel,0);
} }
public void updateModul(Pin arg0) { public void updateModul(Pin arg0) {
if (pins.get(0).getValue()!=slider.getValue()) {
pins.get(0).setValue(slider.getValue());
}
} }
public boolean connect(Arduino arduino) { public boolean connect(Arduino arduino) {
this.addPin(arduino.getPin(5+13));
arduino.getPin(5+13).setObserver(this);
return true; return true;
} }
@Override
public void stateChanged(ChangeEvent arg0) {
if (slider.getValue()==1024) slider.setValue(1023); //Kleiner Trick damit die 1024 angezeigt wird aber keinen Fehler verursacht
pins.get(0).setValue(slider.getValue());
}
} }
...@@ -57,15 +57,15 @@ public class RGB extends Modul { ...@@ -57,15 +57,15 @@ public class RGB extends Modul {
public boolean connect(Arduino arduino) { public boolean connect(Arduino arduino) {
// TODO Pins= R G B ? Aktuell RBG // TODO Pins= R G B ? Aktuell RBG
Pin tmpPin = arduino.getPin(0); Pin tmpPin = arduino.getPin(9);
this.addPin(tmpPin); this.addPin(tmpPin);
tmpPin.setObserver(this); tmpPin.setObserver(this);
tmpPin = arduino.getPin(1); tmpPin = arduino.getPin(10);
this.addPin(tmpPin); this.addPin(tmpPin);
tmpPin.setObserver(this); tmpPin.setObserver(this);
tmpPin = arduino.getPin(2); tmpPin = arduino.getPin(11);
this.addPin(tmpPin); this.addPin(tmpPin);
tmpPin.setObserver(this); tmpPin.setObserver(this);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment